X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-main%2Fusers%2Fuser-notifications.component.ts;h=48be80e3f37f4934f76e8bb18f7ece64339f7c34;hb=66927c0588b050f23ad3f98d62b48307bc7e79e7;hp=6abd8b7d841c1ebd70105dec1a4487fca6a896e0;hpb=67ed6552b831df66713bac9e672738796128d33f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-main/users/user-notifications.component.ts b/client/src/app/shared/shared-main/users/user-notifications.component.ts index 6abd8b7d8..48be80e3f 100644 --- a/client/src/app/shared/shared-main/users/user-notifications.component.ts +++ b/client/src/app/shared/shared-main/users/user-notifications.component.ts @@ -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) + } }