Fix mark all as read notifications

This commit is contained in:
Chocobozzz 2020-01-06 15:59:17 +01:00
parent 93d54cc769
commit bc6f886347
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 25 additions and 17 deletions

View File

@ -4,12 +4,18 @@
Notification preferences Notification preferences
</a> </a>
<button class="btn" [disabled]="!getUnreadNotifications()" (click)="markAllAsRead()"> <button class="btn" [disabled]="!hasUnreadNotifications()" (click)="markAllAsRead()">
<my-global-icon *ngIf="getUnreadNotifications()" iconName="inbox-full"></my-global-icon> <ng-container *ngIf="hasUnreadNotifications()">
<span i18n *ngIf="getUnreadNotifications()">Mark all as read</span> <my-global-icon iconName="inbox-full"></my-global-icon>
<my-global-icon *ngIf="!getUnreadNotifications()" iconName="circle-tick"></my-global-icon> <span i18n>Mark all as read</span>
<span i18n *ngIf="!getUnreadNotifications()">All 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> </button>
</div> </div>

View File

@ -12,7 +12,7 @@ export class MyAccountNotificationsComponent {
this.userNotification.markAllAsRead() this.userNotification.markAllAsRead()
} }
getUnreadNotifications () { hasUnreadNotifications () {
return this.userNotification.notifications.filter(n => n.read === false).length return this.userNotification.notifications.filter(n => n.read === false).length !== 0
} }
} }

View File

@ -31,7 +31,7 @@
<my-user-notifications <my-user-notifications
[ignoreLoadingBar]="true" [infiniteScroll]="false" itemsPerPage="10" [ignoreLoadingBar]="true" [infiniteScroll]="false" itemsPerPage="10"
(notificationsLoaded)="onNotificationLoaded()" [markAllAsReadSubject]="markAllAsReadSubject" (notificationsLoaded)="onNotificationLoaded()"
></my-user-notifications> ></my-user-notifications>
<a *ngIf="loaded" class="all-notifications" routerLink="/my-account/notifications"> <a *ngIf="loaded" class="all-notifications" routerLink="/my-account/notifications">

View File

@ -1,11 +1,12 @@
import { Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core' import { Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'
import { User } from '../shared/users/user.model' import { User } from '../shared/users/user.model'
import { UserNotificationService } from '@app/shared/users/user-notification.service' 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 { Notifier, UserNotificationSocket } from '@app/core'
import { NgbPopover } from '@ng-bootstrap/ng-bootstrap' import { NgbPopover } from '@ng-bootstrap/ng-bootstrap'
import { NavigationEnd, Router } from '@angular/router' import { NavigationEnd, Router } from '@angular/router'
import { filter } from 'rxjs/operators' import { filter } from 'rxjs/operators'
import { UserNotificationsComponent } from '@app/shared'
@Component({ @Component({
selector: 'my-avatar-notification', selector: 'my-avatar-notification',
@ -14,11 +15,14 @@ import { filter } from 'rxjs/operators'
}) })
export class AvatarNotificationComponent implements OnInit, OnDestroy { export class AvatarNotificationComponent implements OnInit, OnDestroy {
@ViewChild('popover', { static: true }) popover: NgbPopover @ViewChild('popover', { static: true }) popover: NgbPopover
@Input() user: User @Input() user: User
unreadNotifications = 0 unreadNotifications = 0
loaded = false loaded = false
markAllAsReadSubject = new Subject<boolean>()
private notificationSub: Subscription private notificationSub: Subscription
private routeSub: Subscription private routeSub: Subscription
@ -64,14 +68,7 @@ export class AvatarNotificationComponent implements OnInit, OnDestroy {
} }
markAllAsRead () { markAllAsRead () {
this.userNotificationService.markAllAsRead() this.markAllAsReadSubject.next(true)
.subscribe(
() => {
this.unreadNotifications = 0
},
err => this.notifier.error(err.message)
)
} }
private async subscribeToNotifications () { private async subscribeToNotifications () {

View File

@ -15,6 +15,7 @@ export class UserNotificationsComponent implements OnInit {
@Input() ignoreLoadingBar = false @Input() ignoreLoadingBar = false
@Input() infiniteScroll = true @Input() infiniteScroll = true
@Input() itemsPerPage = 20 @Input() itemsPerPage = 20
@Input() markAllAsReadSubject: Subject<boolean>
@Output() notificationsLoaded = new EventEmitter() @Output() notificationsLoaded = new EventEmitter()
@ -40,6 +41,10 @@ export class UserNotificationsComponent implements OnInit {
} }
this.loadMoreNotifications() this.loadMoreNotifications()
if (this.markAllAsReadSubject) {
this.markAllAsReadSubject.subscribe(() => this.markAllAsRead())
}
} }
loadMoreNotifications () { loadMoreNotifications () {