]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix mark all as read notifications
authorChocobozzz <me@florianbigard.com>
Mon, 6 Jan 2020 14:59:17 +0000 (15:59 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 6 Jan 2020 14:59:17 +0000 (15:59 +0100)
client/src/app/+my-account/my-account-notifications/my-account-notifications.component.html
client/src/app/+my-account/my-account-notifications/my-account-notifications.component.ts
client/src/app/menu/avatar-notification.component.html
client/src/app/menu/avatar-notification.component.ts
client/src/app/shared/users/user-notifications.component.ts

index daf721f033fccb32d658025dc15382725079c06a..dec3b14cc123acc0e14c7fca2d2d4ba10f06c2cb 100644 (file)
@@ -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>
 
index 156e7713d48e7a87ee1ba64f00ae6b14c91a0502..a50cb0fb94f60d7b6c819163fadaa7f5334cc519 100644 (file)
@@ -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
   }
 }
index 8ffec46da64ca72cdec242c80a71f716b316291b..7975afba509778fc0b552e95745192edd743ef2a 100644 (file)
@@ -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">
index ff830ac1c310cd221fcc5247df7ca6b00488ebd9..989a11849d38515a2e9010f57b896566f7744fa3 100644 (file)
@@ -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 () {
index 3c9eb369d3c54b0268b611cd4ada48c2e73735e9..977dd8925c80eea6db5703f7eb7f21d00f41ef7c 100644 (file)
@@ -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 () {