diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:10:17 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 67ed6552b831df66713bac9e672738796128d33f (patch) | |
tree | 59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/users/user-notifications.component.ts | |
parent | 0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff) | |
download | PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip |
Reorganize client shared modules
Diffstat (limited to 'client/src/app/shared/users/user-notifications.component.ts')
-rw-r--r-- | client/src/app/shared/users/user-notifications.component.ts | 101 |
1 files changed, 0 insertions, 101 deletions
diff --git a/client/src/app/shared/users/user-notifications.component.ts b/client/src/app/shared/users/user-notifications.component.ts deleted file mode 100644 index 977dd8925..000000000 --- a/client/src/app/shared/users/user-notifications.component.ts +++ /dev/null | |||
@@ -1,101 +0,0 @@ | |||
1 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' | ||
2 | import { UserNotificationService } from '@app/shared/users/user-notification.service' | ||
3 | import { UserNotificationType } from '../../../../../shared' | ||
4 | import { ComponentPagination, hasMoreItems } from '@app/shared/rest/component-pagination.model' | ||
5 | import { Notifier } from '@app/core' | ||
6 | import { UserNotification } from '@app/shared/users/user-notification.model' | ||
7 | import { Subject } from 'rxjs' | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-user-notifications', | ||
11 | templateUrl: 'user-notifications.component.html', | ||
12 | styleUrls: [ 'user-notifications.component.scss' ] | ||
13 | }) | ||
14 | export class UserNotificationsComponent implements OnInit { | ||
15 | @Input() ignoreLoadingBar = false | ||
16 | @Input() infiniteScroll = true | ||
17 | @Input() itemsPerPage = 20 | ||
18 | @Input() markAllAsReadSubject: Subject<boolean> | ||
19 | |||
20 | @Output() notificationsLoaded = new EventEmitter() | ||
21 | |||
22 | notifications: UserNotification[] = [] | ||
23 | |||
24 | // So we can access it in the template | ||
25 | UserNotificationType = UserNotificationType | ||
26 | |||
27 | componentPagination: ComponentPagination | ||
28 | |||
29 | onDataSubject = new Subject<any[]>() | ||
30 | |||
31 | constructor ( | ||
32 | private userNotificationService: UserNotificationService, | ||
33 | private notifier: Notifier | ||
34 | ) { } | ||
35 | |||
36 | ngOnInit () { | ||
37 | this.componentPagination = { | ||
38 | currentPage: 1, | ||
39 | itemsPerPage: this.itemsPerPage, // Reset items per page, because of the @Input() variable | ||
40 | totalItems: null | ||
41 | } | ||
42 | |||
43 | this.loadMoreNotifications() | ||
44 | |||
45 | if (this.markAllAsReadSubject) { | ||
46 | this.markAllAsReadSubject.subscribe(() => this.markAllAsRead()) | ||
47 | } | ||
48 | } | ||
49 | |||
50 | loadMoreNotifications () { | ||
51 | this.userNotificationService.listMyNotifications(this.componentPagination, undefined, this.ignoreLoadingBar) | ||
52 | .subscribe( | ||
53 | result => { | ||
54 | this.notifications = this.notifications.concat(result.data) | ||
55 | this.componentPagination.totalItems = result.total | ||
56 | |||
57 | this.notificationsLoaded.emit() | ||
58 | |||
59 | this.onDataSubject.next(result.data) | ||
60 | }, | ||
61 | |||
62 | err => this.notifier.error(err.message) | ||
63 | ) | ||
64 | } | ||
65 | |||
66 | onNearOfBottom () { | ||
67 | if (this.infiniteScroll === false) return | ||
68 | |||
69 | this.componentPagination.currentPage++ | ||
70 | |||
71 | if (hasMoreItems(this.componentPagination)) { | ||
72 | this.loadMoreNotifications() | ||
73 | } | ||
74 | } | ||
75 | |||
76 | markAsRead (notification: UserNotification) { | ||
77 | if (notification.read) return | ||
78 | |||
79 | this.userNotificationService.markAsRead(notification) | ||
80 | .subscribe( | ||
81 | () => { | ||
82 | notification.read = true | ||
83 | }, | ||
84 | |||
85 | err => this.notifier.error(err.message) | ||
86 | ) | ||
87 | } | ||
88 | |||
89 | markAllAsRead () { | ||
90 | this.userNotificationService.markAllAsRead() | ||
91 | .subscribe( | ||
92 | () => { | ||
93 | for (const notification of this.notifications) { | ||
94 | notification.read = true | ||
95 | } | ||
96 | }, | ||
97 | |||
98 | err => this.notifier.error(err.message) | ||
99 | ) | ||
100 | } | ||
101 | } | ||