aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-main
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-07-15 11:15:50 +0200
committerRigel Kent <par@rigelk.eu>2020-07-29 18:15:53 +0200
commit654a188f80fc1f089aa14837084664c908fe27d2 (patch)
tree63855915278c1a3aeb1509c09a7a2f5ee6977893 /client/src/app/shared/shared-main
parent292c17b894e430d61f9197fb6fa245f5f9c6fa7c (diff)
downloadPeerTube-654a188f80fc1f089aa14837084664c908fe27d2.tar.gz
PeerTube-654a188f80fc1f089aa14837084664c908fe27d2.tar.zst
PeerTube-654a188f80fc1f089aa14837084664c908fe27d2.zip
allow sorting notifications
Diffstat (limited to 'client/src/app/shared/shared-main')
-rw-r--r--client/src/app/shared/shared-main/users/user-notification.service.ts14
-rw-r--r--client/src/app/shared/shared-main/users/user-notifications.component.ts28
2 files changed, 34 insertions, 8 deletions
diff --git a/client/src/app/shared/shared-main/users/user-notification.service.ts b/client/src/app/shared/shared-main/users/user-notification.service.ts
index 8dd9472fe..ecc66ecdb 100644
--- a/client/src/app/shared/shared-main/users/user-notification.service.ts
+++ b/client/src/app/shared/shared-main/users/user-notification.service.ts
@@ -5,6 +5,7 @@ import { ComponentPaginationLight, RestExtractor, RestService, User, UserNotific
5import { ResultList, UserNotification as UserNotificationServer, UserNotificationSetting } from '@shared/models' 5import { ResultList, UserNotification as UserNotificationServer, UserNotificationSetting } from '@shared/models'
6import { environment } from '../../../../environments/environment' 6import { environment } from '../../../../environments/environment'
7import { UserNotification } from './user-notification.model' 7import { UserNotification } from './user-notification.model'
8import { SortMeta } from 'primeng/api'
8 9
9@Injectable() 10@Injectable()
10export class UserNotificationService { 11export class UserNotificationService {
@@ -18,9 +19,16 @@ export class UserNotificationService {
18 private userNotificationSocket: UserNotificationSocket 19 private userNotificationSocket: UserNotificationSocket
19 ) {} 20 ) {}
20 21
21 listMyNotifications (pagination: ComponentPaginationLight, unread?: boolean, ignoreLoadingBar = false) { 22 listMyNotifications (parameters: {
23 pagination: ComponentPaginationLight
24 ignoreLoadingBar?: boolean
25 unread?: boolean,
26 sort?: SortMeta
27 }) {
28 const { pagination, ignoreLoadingBar, unread, sort } = parameters
29
22 let params = new HttpParams() 30 let params = new HttpParams()
23 params = this.restService.addRestGetParams(params, this.restService.componentPaginationToRestPagination(pagination)) 31 params = this.restService.addRestGetParams(params, this.restService.componentPaginationToRestPagination(pagination), sort)
24 32
25 if (unread) params = params.append('unread', `${unread}`) 33 if (unread) params = params.append('unread', `${unread}`)
26 34
@@ -35,7 +43,7 @@ export class UserNotificationService {
35 } 43 }
36 44
37 countUnreadNotifications () { 45 countUnreadNotifications () {
38 return this.listMyNotifications({ currentPage: 1, itemsPerPage: 0 }, true) 46 return this.listMyNotifications({ pagination: { currentPage: 1, itemsPerPage: 0 }, ignoreLoadingBar: true, unread: true })
39 .pipe(map(n => n.total)) 47 .pipe(map(n => n.total))
40 } 48 }
41 49
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 {
19 @Output() notificationsLoaded = new EventEmitter() 19 @Output() notificationsLoaded = new EventEmitter()
20 20
21 notifications: UserNotification[] = [] 21 notifications: UserNotification[] = []
22 sortField = 'createdAt'
22 23
23 // So we can access it in the template 24 // So we can access it in the template
24 UserNotificationType = UserNotificationType 25 UserNotificationType = UserNotificationType
@@ -39,18 +40,25 @@ export class UserNotificationsComponent implements OnInit {
39 totalItems: null 40 totalItems: null
40 } 41 }
41 42
42 this.loadMoreNotifications() 43 this.loadNotifications()
43 44
44 if (this.markAllAsReadSubject) { 45 if (this.markAllAsReadSubject) {
45 this.markAllAsReadSubject.subscribe(() => this.markAllAsRead()) 46 this.markAllAsReadSubject.subscribe(() => this.markAllAsRead())
46 } 47 }
47 } 48 }
48 49
49 loadMoreNotifications () { 50 loadNotifications (reset?: boolean) {
50 this.userNotificationService.listMyNotifications(this.componentPagination, undefined, this.ignoreLoadingBar) 51 this.userNotificationService.listMyNotifications({
52 pagination: this.componentPagination,
53 ignoreLoadingBar: this.ignoreLoadingBar,
54 sort: {
55 field: this.sortField,
56 order: this.sortField === 'createdAt' ? -1 : 1
57 }
58 })
51 .subscribe( 59 .subscribe(
52 result => { 60 result => {
53 this.notifications = this.notifications.concat(result.data) 61 this.notifications = reset ? result.data : this.notifications.concat(result.data)
54 this.componentPagination.totalItems = result.total 62 this.componentPagination.totalItems = result.total
55 63
56 this.notificationsLoaded.emit() 64 this.notificationsLoaded.emit()
@@ -68,7 +76,7 @@ export class UserNotificationsComponent implements OnInit {
68 this.componentPagination.currentPage++ 76 this.componentPagination.currentPage++
69 77
70 if (hasMoreItems(this.componentPagination)) { 78 if (hasMoreItems(this.componentPagination)) {
71 this.loadMoreNotifications() 79 this.loadNotifications()
72 } 80 }
73 } 81 }
74 82
@@ -97,4 +105,14 @@ export class UserNotificationsComponent implements OnInit {
97 err => this.notifier.error(err.message) 105 err => this.notifier.error(err.message)
98 ) 106 )
99 } 107 }
108
109 changeSortColumn (column: string) {
110 this.componentPagination = {
111 currentPage: 1,
112 itemsPerPage: this.itemsPerPage,
113 totalItems: null
114 }
115 this.sortField = column
116 this.loadNotifications(true)
117 }
100} 118}