diff options
5 files changed, 25 insertions, 17 deletions
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 @@ | |||
4 | Notification preferences | 4 | Notification preferences |
5 | </a> | 5 | </a> |
6 | 6 | ||
7 | <button class="btn" [disabled]="!getUnreadNotifications()" (click)="markAllAsRead()"> | 7 | <button class="btn" [disabled]="!hasUnreadNotifications()" (click)="markAllAsRead()"> |
8 | <my-global-icon *ngIf="getUnreadNotifications()" iconName="inbox-full"></my-global-icon> | 8 | <ng-container *ngIf="hasUnreadNotifications()"> |
9 | <span i18n *ngIf="getUnreadNotifications()">Mark all as read</span> | 9 | <my-global-icon iconName="inbox-full"></my-global-icon> |
10 | 10 | ||
11 | <my-global-icon *ngIf="!getUnreadNotifications()" iconName="circle-tick"></my-global-icon> | 11 | <span i18n>Mark all as read</span> |
12 | <span i18n *ngIf="!getUnreadNotifications()">All read</span> | 12 | </ng-container> |
13 | |||
14 | <ng-container *ngIf="!hasUnreadNotifications()"> | ||
15 | <my-global-icon iconName="circle-tick"></my-global-icon> | ||
16 | |||
17 | <span i18n>All read</span> | ||
18 | </ng-container> | ||
13 | </button> | 19 | </button> |
14 | </div> | 20 | </div> |
15 | 21 | ||
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 { | |||
12 | this.userNotification.markAllAsRead() | 12 | this.userNotification.markAllAsRead() |
13 | } | 13 | } |
14 | 14 | ||
15 | getUnreadNotifications () { | 15 | hasUnreadNotifications () { |
16 | return this.userNotification.notifications.filter(n => n.read === false).length | 16 | return this.userNotification.notifications.filter(n => n.read === false).length !== 0 |
17 | } | 17 | } |
18 | } | 18 | } |
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 @@ | |||
31 | 31 | ||
32 | <my-user-notifications | 32 | <my-user-notifications |
33 | [ignoreLoadingBar]="true" [infiniteScroll]="false" itemsPerPage="10" | 33 | [ignoreLoadingBar]="true" [infiniteScroll]="false" itemsPerPage="10" |
34 | (notificationsLoaded)="onNotificationLoaded()" | 34 | [markAllAsReadSubject]="markAllAsReadSubject" (notificationsLoaded)="onNotificationLoaded()" |
35 | ></my-user-notifications> | 35 | ></my-user-notifications> |
36 | 36 | ||
37 | <a *ngIf="loaded" class="all-notifications" routerLink="/my-account/notifications"> | 37 | <a *ngIf="loaded" class="all-notifications" routerLink="/my-account/notifications"> |
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 @@ | |||
1 | import { Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core' | 1 | import { Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core' |
2 | import { User } from '../shared/users/user.model' | 2 | import { User } from '../shared/users/user.model' |
3 | import { UserNotificationService } from '@app/shared/users/user-notification.service' | 3 | import { UserNotificationService } from '@app/shared/users/user-notification.service' |
4 | import { Subscription } from 'rxjs' | 4 | import { Subject, Subscription } from 'rxjs' |
5 | import { Notifier, UserNotificationSocket } from '@app/core' | 5 | import { Notifier, UserNotificationSocket } from '@app/core' |
6 | import { NgbPopover } from '@ng-bootstrap/ng-bootstrap' | 6 | import { NgbPopover } from '@ng-bootstrap/ng-bootstrap' |
7 | import { NavigationEnd, Router } from '@angular/router' | 7 | import { NavigationEnd, Router } from '@angular/router' |
8 | import { filter } from 'rxjs/operators' | 8 | import { filter } from 'rxjs/operators' |
9 | import { UserNotificationsComponent } from '@app/shared' | ||
9 | 10 | ||
10 | @Component({ | 11 | @Component({ |
11 | selector: 'my-avatar-notification', | 12 | selector: 'my-avatar-notification', |
@@ -14,11 +15,14 @@ import { filter } from 'rxjs/operators' | |||
14 | }) | 15 | }) |
15 | export class AvatarNotificationComponent implements OnInit, OnDestroy { | 16 | export class AvatarNotificationComponent implements OnInit, OnDestroy { |
16 | @ViewChild('popover', { static: true }) popover: NgbPopover | 17 | @ViewChild('popover', { static: true }) popover: NgbPopover |
18 | |||
17 | @Input() user: User | 19 | @Input() user: User |
18 | 20 | ||
19 | unreadNotifications = 0 | 21 | unreadNotifications = 0 |
20 | loaded = false | 22 | loaded = false |
21 | 23 | ||
24 | markAllAsReadSubject = new Subject<boolean>() | ||
25 | |||
22 | private notificationSub: Subscription | 26 | private notificationSub: Subscription |
23 | private routeSub: Subscription | 27 | private routeSub: Subscription |
24 | 28 | ||
@@ -64,14 +68,7 @@ export class AvatarNotificationComponent implements OnInit, OnDestroy { | |||
64 | } | 68 | } |
65 | 69 | ||
66 | markAllAsRead () { | 70 | markAllAsRead () { |
67 | this.userNotificationService.markAllAsRead() | 71 | this.markAllAsReadSubject.next(true) |
68 | .subscribe( | ||
69 | () => { | ||
70 | this.unreadNotifications = 0 | ||
71 | }, | ||
72 | |||
73 | err => this.notifier.error(err.message) | ||
74 | ) | ||
75 | } | 72 | } |
76 | 73 | ||
77 | private async subscribeToNotifications () { | 74 | 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 { | |||
15 | @Input() ignoreLoadingBar = false | 15 | @Input() ignoreLoadingBar = false |
16 | @Input() infiniteScroll = true | 16 | @Input() infiniteScroll = true |
17 | @Input() itemsPerPage = 20 | 17 | @Input() itemsPerPage = 20 |
18 | @Input() markAllAsReadSubject: Subject<boolean> | ||
18 | 19 | ||
19 | @Output() notificationsLoaded = new EventEmitter() | 20 | @Output() notificationsLoaded = new EventEmitter() |
20 | 21 | ||
@@ -40,6 +41,10 @@ export class UserNotificationsComponent implements OnInit { | |||
40 | } | 41 | } |
41 | 42 | ||
42 | this.loadMoreNotifications() | 43 | this.loadMoreNotifications() |
44 | |||
45 | if (this.markAllAsReadSubject) { | ||
46 | this.markAllAsReadSubject.subscribe(() => this.markAllAsRead()) | ||
47 | } | ||
43 | } | 48 | } |
44 | 49 | ||
45 | loadMoreNotifications () { | 50 | loadMoreNotifications () { |