]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+my-account/my-account-notifications/my-account-notifications.component.ts
harmonize search for libraries
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-notifications / my-account-notifications.component.ts
index 8a51319fe5bc752769fcf31535856e77965f067d..0ec67d4016bd0c0c3019e82aa0486b2119f5a37d 100644 (file)
@@ -1,6 +1,8 @@
 import { Component, ViewChild } from '@angular/core'
 import { UserNotificationsComponent } from '@app/shared/shared-main'
 
+type NotificationSortType = 'createdAt' | 'read'
+
 @Component({
   templateUrl: './my-account-notifications.component.html',
   styleUrls: [ './my-account-notifications.component.scss' ]
@@ -8,7 +10,17 @@ import { UserNotificationsComponent } from '@app/shared/shared-main'
 export class MyAccountNotificationsComponent {
   @ViewChild('userNotification', { static: true }) userNotification: UserNotificationsComponent
 
-  notificationSortType = 'created'
+  _notificationSortType: NotificationSortType = 'createdAt'
+
+  get notificationSortType () {
+    return !this.hasUnreadNotifications()
+      ? 'createdAt'
+      : this._notificationSortType
+  }
+
+  set notificationSortType (type: NotificationSortType) {
+    this._notificationSortType = type
+  }
 
   markAllAsRead () {
     this.userNotification.markAllAsRead()
@@ -17,4 +29,8 @@ export class MyAccountNotificationsComponent {
   hasUnreadNotifications () {
     return this.userNotification.notifications.filter(n => n.read === false).length !== 0
   }
+
+  onChangeSortColumn () {
+    this.userNotification.changeSortColumn(this.notificationSortType)
+  }
 }