From bc6f886347f676220847461600122cde86edc272 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 6 Jan 2020 15:59:17 +0100 Subject: Fix mark all as read notifications --- .../my-account-notifications.component.html | 16 +++++++++++----- .../my-account-notifications.component.ts | 4 ++-- client/src/app/menu/avatar-notification.component.html | 2 +- client/src/app/menu/avatar-notification.component.ts | 15 ++++++--------- .../src/app/shared/users/user-notifications.component.ts | 5 +++++ 5 files changed, 25 insertions(+), 17 deletions(-) (limited to 'client/src/app') diff --git a/client/src/app/+my-account/my-account-notifications/my-account-notifications.component.html b/client/src/app/+my-account/my-account-notifications/my-account-notifications.component.html index daf721f03..dec3b14cc 100644 --- a/client/src/app/+my-account/my-account-notifications/my-account-notifications.component.html +++ b/client/src/app/+my-account/my-account-notifications/my-account-notifications.component.html @@ -4,12 +4,18 @@ Notification preferences - diff --git a/client/src/app/+my-account/my-account-notifications/my-account-notifications.component.ts b/client/src/app/+my-account/my-account-notifications/my-account-notifications.component.ts index 156e7713d..a50cb0fb9 100644 --- a/client/src/app/+my-account/my-account-notifications/my-account-notifications.component.ts +++ b/client/src/app/+my-account/my-account-notifications/my-account-notifications.component.ts @@ -12,7 +12,7 @@ export class MyAccountNotificationsComponent { this.userNotification.markAllAsRead() } - getUnreadNotifications () { - return this.userNotification.notifications.filter(n => n.read === false).length + hasUnreadNotifications () { + return this.userNotification.notifications.filter(n => n.read === false).length !== 0 } } diff --git a/client/src/app/menu/avatar-notification.component.html b/client/src/app/menu/avatar-notification.component.html index 8ffec46da..7975afba5 100644 --- a/client/src/app/menu/avatar-notification.component.html +++ b/client/src/app/menu/avatar-notification.component.html @@ -31,7 +31,7 @@ diff --git a/client/src/app/menu/avatar-notification.component.ts b/client/src/app/menu/avatar-notification.component.ts index ff830ac1c..989a11849 100644 --- a/client/src/app/menu/avatar-notification.component.ts +++ b/client/src/app/menu/avatar-notification.component.ts @@ -1,11 +1,12 @@ import { Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core' import { User } from '../shared/users/user.model' import { UserNotificationService } from '@app/shared/users/user-notification.service' -import { Subscription } from 'rxjs' +import { Subject, Subscription } from 'rxjs' import { Notifier, UserNotificationSocket } from '@app/core' import { NgbPopover } from '@ng-bootstrap/ng-bootstrap' import { NavigationEnd, Router } from '@angular/router' import { filter } from 'rxjs/operators' +import { UserNotificationsComponent } from '@app/shared' @Component({ selector: 'my-avatar-notification', @@ -14,11 +15,14 @@ import { filter } from 'rxjs/operators' }) export class AvatarNotificationComponent implements OnInit, OnDestroy { @ViewChild('popover', { static: true }) popover: NgbPopover + @Input() user: User unreadNotifications = 0 loaded = false + markAllAsReadSubject = new Subject() + private notificationSub: Subscription private routeSub: Subscription @@ -64,14 +68,7 @@ export class AvatarNotificationComponent implements OnInit, OnDestroy { } markAllAsRead () { - this.userNotificationService.markAllAsRead() - .subscribe( - () => { - this.unreadNotifications = 0 - }, - - err => this.notifier.error(err.message) - ) + this.markAllAsReadSubject.next(true) } private async subscribeToNotifications () { diff --git a/client/src/app/shared/users/user-notifications.component.ts b/client/src/app/shared/users/user-notifications.component.ts index 3c9eb369d..977dd8925 100644 --- a/client/src/app/shared/users/user-notifications.component.ts +++ b/client/src/app/shared/users/user-notifications.component.ts @@ -15,6 +15,7 @@ export class UserNotificationsComponent implements OnInit { @Input() ignoreLoadingBar = false @Input() infiniteScroll = true @Input() itemsPerPage = 20 + @Input() markAllAsReadSubject: Subject @Output() notificationsLoaded = new EventEmitter() @@ -40,6 +41,10 @@ export class UserNotificationsComponent implements OnInit { } this.loadMoreNotifications() + + if (this.markAllAsReadSubject) { + this.markAllAsReadSubject.subscribe(() => this.markAllAsRead()) + } } loadMoreNotifications () { -- cgit v1.2.3