]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-main/users/user-notifications.component.ts
modify user-quota to match account settings style
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / users / user-notifications.component.ts
index 6abd8b7d841c1ebd70105dec1a4487fca6a896e0..48be80e3f37f4934f76e8bb18f7ece64339f7c34 100644 (file)
@@ -19,6 +19,7 @@ export class UserNotificationsComponent implements OnInit {
   @Output() notificationsLoaded = new EventEmitter()
 
   notifications: UserNotification[] = []
+  sortField = 'createdAt'
 
   // So we can access it in the template
   UserNotificationType = UserNotificationType
@@ -39,18 +40,25 @@ export class UserNotificationsComponent implements OnInit {
       totalItems: null
     }
 
-    this.loadMoreNotifications()
+    this.loadNotifications()
 
     if (this.markAllAsReadSubject) {
       this.markAllAsReadSubject.subscribe(() => this.markAllAsRead())
     }
   }
 
-  loadMoreNotifications () {
-    this.userNotificationService.listMyNotifications(this.componentPagination, undefined, this.ignoreLoadingBar)
+  loadNotifications (reset?: boolean) {
+    this.userNotificationService.listMyNotifications({
+      pagination: this.componentPagination,
+      ignoreLoadingBar: this.ignoreLoadingBar,
+      sort: {
+        field: this.sortField,
+        order: this.sortField === 'createdAt' ? -1 : 1
+      }
+    })
         .subscribe(
           result => {
-            this.notifications = this.notifications.concat(result.data)
+            this.notifications = reset ? result.data : this.notifications.concat(result.data)
             this.componentPagination.totalItems = result.total
 
             this.notificationsLoaded.emit()
@@ -68,7 +76,7 @@ export class UserNotificationsComponent implements OnInit {
     this.componentPagination.currentPage++
 
     if (hasMoreItems(this.componentPagination)) {
-      this.loadMoreNotifications()
+      this.loadNotifications()
     }
   }
 
@@ -97,4 +105,14 @@ export class UserNotificationsComponent implements OnInit {
           err => this.notifier.error(err.message)
         )
   }
+
+  changeSortColumn (column: string) {
+    this.componentPagination = {
+      currentPage: 1,
+      itemsPerPage: this.itemsPerPage,
+      totalItems: null
+    }
+    this.sortField = column
+    this.loadNotifications(true)
+  }
 }