Notification preferences
</a>
- <button class="btn" [disabled]="!getUnreadNotifications()" (click)="markAllAsRead()">
- <my-global-icon *ngIf="getUnreadNotifications()" iconName="inbox-full"></my-global-icon>
- <span i18n *ngIf="getUnreadNotifications()">Mark all as read</span>
+ <button class="btn" [disabled]="!hasUnreadNotifications()" (click)="markAllAsRead()">
+ <ng-container *ngIf="hasUnreadNotifications()">
+ <my-global-icon iconName="inbox-full"></my-global-icon>
- <my-global-icon *ngIf="!getUnreadNotifications()" iconName="circle-tick"></my-global-icon>
- <span i18n *ngIf="!getUnreadNotifications()">All read</span>
+ <span i18n>Mark all as read</span>
+ </ng-container>
+
+ <ng-container *ngIf="!hasUnreadNotifications()">
+ <my-global-icon iconName="circle-tick"></my-global-icon>
+
+ <span i18n>All read</span>
+ </ng-container>
</button>
</div>
<my-user-notifications
[ignoreLoadingBar]="true" [infiniteScroll]="false" itemsPerPage="10"
- (notificationsLoaded)="onNotificationLoaded()"
+ [markAllAsReadSubject]="markAllAsReadSubject" (notificationsLoaded)="onNotificationLoaded()"
></my-user-notifications>
<a *ngIf="loaded" class="all-notifications" routerLink="/my-account/notifications">
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',
})
export class AvatarNotificationComponent implements OnInit, OnDestroy {
@ViewChild('popover', { static: true }) popover: NgbPopover
+
@Input() user: User
unreadNotifications = 0
loaded = false
+ markAllAsReadSubject = new Subject<boolean>()
+
private notificationSub: Subscription
private routeSub: Subscription
}
markAllAsRead () {
- this.userNotificationService.markAllAsRead()
- .subscribe(
- () => {
- this.unreadNotifications = 0
- },
-
- err => this.notifier.error(err.message)
- )
+ this.markAllAsReadSubject.next(true)
}
private async subscribeToNotifications () {
@Input() ignoreLoadingBar = false
@Input() infiniteScroll = true
@Input() itemsPerPage = 20
+ @Input() markAllAsReadSubject: Subject<boolean>
@Output() notificationsLoaded = new EventEmitter()
}
this.loadMoreNotifications()
+
+ if (this.markAllAsReadSubject) {
+ this.markAllAsReadSubject.subscribe(() => this.markAllAsRead())
+ }
}
loadMoreNotifications () {