Fix mark all as read notifications
This commit is contained in:
parent
93d54cc769
commit
bc6f886347
|
@ -4,12 +4,18 @@
|
|||
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>
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
<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">
|
||||
|
|
|
@ -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<boolean>()
|
||||
|
||||
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 () {
|
||||
|
|
|
@ -15,6 +15,7 @@ export class UserNotificationsComponent implements OnInit {
|
|||
@Input() ignoreLoadingBar = false
|
||||
@Input() infiniteScroll = true
|
||||
@Input() itemsPerPage = 20
|
||||
@Input() markAllAsReadSubject: Subject<boolean>
|
||||
|
||||
@Output() notificationsLoaded = new EventEmitter()
|
||||
|
||||
|
@ -40,6 +41,10 @@ export class UserNotificationsComponent implements OnInit {
|
|||
}
|
||||
|
||||
this.loadMoreNotifications()
|
||||
|
||||
if (this.markAllAsReadSubject) {
|
||||
this.markAllAsReadSubject.subscribe(() => this.markAllAsRead())
|
||||
}
|
||||
}
|
||||
|
||||
loadMoreNotifications () {
|
||||
|
|
Loading…
Reference in New Issue