]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-library/my-history/my-history.component.ts
Added translation using Weblate (Chinese (Simplified) (zh_HANT-TW))
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / my-history / my-history.component.ts
CommitLineData
5bcbcbe3 1import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core'
80bfd33c 2import { ActivatedRoute, Router } from '@angular/router'
67ed6552
C
3import {
4 AuthService,
5 ComponentPagination,
6 ConfirmService,
7 LocalStorageService,
8 Notifier,
9 ScreenService,
10 ServerService,
11 UserService
12} from '@app/core'
13import { immutableAssign } from '@app/helpers'
14import { UserHistoryService } from '@app/shared/shared-main'
15import { AbstractVideoList } from '@app/shared/shared-video-miniature'
d8b34ee5
RK
16import { Subject } from 'rxjs'
17import { debounceTime, tap, distinctUntilChanged } from 'rxjs/operators'
80bfd33c
C
18
19@Component({
17119e4a
C
20 templateUrl: './my-history.component.html',
21 styleUrls: [ './my-history.component.scss' ]
80bfd33c 22})
17119e4a 23export class MyHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy {
80bfd33c 24 titlePage: string
80bfd33c
C
25 pagination: ComponentPagination = {
26 currentPage: 1,
27 itemsPerPage: 5,
28 totalItems: null
29 }
276d9652 30 videosHistoryEnabled: boolean
d8b34ee5
RK
31 search: string
32
33 protected searchStream: Subject<string>
80bfd33c 34
80bfd33c
C
35 constructor (
36 protected router: Router,
489290b8 37 protected serverService: ServerService,
80bfd33c
C
38 protected route: ActivatedRoute,
39 protected authService: AuthService,
276d9652 40 protected userService: UserService,
f8b2c1b4 41 protected notifier: Notifier,
80bfd33c 42 protected screenService: ScreenService,
d3217560 43 protected storageService: LocalStorageService,
80bfd33c 44 private confirmService: ConfirmService,
5bcbcbe3
RK
45 private userHistoryService: UserHistoryService,
46 protected cfr: ComponentFactoryResolver
80bfd33c
C
47 ) {
48 super()
49
d8b34ee5 50 this.titlePage = $localize`My watch history`
80bfd33c
C
51 }
52
53 ngOnInit () {
54 super.ngOnInit()
276d9652 55
4f926722
C
56 this.authService.userInformationLoaded
57 .subscribe(() => {
58 this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
59 })
60
d8b34ee5
RK
61 this.searchStream = new Subject()
62
63 this.searchStream
64 .pipe(
65 debounceTime(400),
66 distinctUntilChanged()
67 )
68 .subscribe(search => {
69 this.search = search
70 this.reloadVideos()
71 })
72 }
73
74 onSearch (event: Event) {
75 const target = event.target as HTMLInputElement
76 this.searchStream.next(target.value)
77 }
78
79 resetSearch () {
80 const searchInput = document.getElementById('history-search') as HTMLInputElement
81 searchInput.value = ''
82 this.searchStream.next('')
80bfd33c
C
83 }
84
85 ngOnDestroy () {
86 super.ngOnDestroy()
87 }
88
89 getVideosObservable (page: number) {
90 const newPagination = immutableAssign(this.pagination, { currentPage: page })
91
d8b34ee5
RK
92 return this.userHistoryService.getUserVideosHistory(newPagination, this.search)
93 .pipe(
94 tap(res => this.pagination.totalItems = res.total)
95 )
80bfd33c
C
96 }
97
98 generateSyndicationList () {
5bcbcbe3 99 /* method disabled */
80bfd33c
C
100 throw new Error('Method not implemented.')
101 }
276d9652
C
102
103 onVideosHistoryChange () {
104 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
105 .subscribe(
106 () => {
107 const message = this.videosHistoryEnabled === true ?
66357162
C
108 $localize`Videos history is enabled` :
109 $localize`Videos history is disabled`
276d9652 110
f8b2c1b4 111 this.notifier.success(message)
276d9652
C
112
113 this.authService.refreshUserInformation()
114 },
115
f8b2c1b4 116 err => this.notifier.error(err.message)
276d9652
C
117 )
118 }
119
120 async deleteHistory () {
66357162
C
121 const title = $localize`Delete videos history`
122 const message = $localize`Are you sure you want to delete all your videos history?`
276d9652
C
123
124 const res = await this.confirmService.confirm(message, title)
125 if (res !== true) return
126
127 this.userHistoryService.deleteUserVideosHistory()
128 .subscribe(
129 () => {
66357162 130 this.notifier.success($localize`Videos history deleted`)
276d9652
C
131
132 this.reloadVideos()
133 },
134
f8b2c1b4 135 err => this.notifier.error(err.message)
276d9652
C
136 )
137 }
80bfd33c 138}