1 import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
13 import { immutableAssign } from '@app/helpers'
14 import { UserHistoryService } from '@app/shared/shared-main'
15 import { AbstractVideoList } from '@app/shared/shared-video-miniature'
16 import { Subject } from 'rxjs'
17 import { debounceTime, tap, distinctUntilChanged } from 'rxjs/operators'
20 templateUrl: './my-history.component.html',
21 styleUrls: [ './my-history.component.scss' ]
23 export class MyHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy {
25 pagination: ComponentPagination = {
30 videosHistoryEnabled: boolean
33 protected searchStream: Subject<string>
36 protected router: Router,
37 protected serverService: ServerService,
38 protected route: ActivatedRoute,
39 protected authService: AuthService,
40 protected userService: UserService,
41 protected notifier: Notifier,
42 protected screenService: ScreenService,
43 protected storageService: LocalStorageService,
44 private confirmService: ConfirmService,
45 private userHistoryService: UserHistoryService,
46 protected cfr: ComponentFactoryResolver
50 this.titlePage = $localize`My watch history`
56 this.authService.userInformationLoaded
58 this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
61 this.searchStream = new Subject()
66 distinctUntilChanged()
68 .subscribe(search => {
74 onSearch (event: Event) {
75 const target = event.target as HTMLInputElement
76 this.searchStream.next(target.value)
80 const searchInput = document.getElementById('history-search') as HTMLInputElement
81 searchInput.value = ''
82 this.searchStream.next('')
89 getVideosObservable (page: number) {
90 const newPagination = immutableAssign(this.pagination, { currentPage: page })
92 return this.userHistoryService.getUserVideosHistory(newPagination, this.search)
94 tap(res => this.pagination.totalItems = res.total)
98 generateSyndicationList () {
100 throw new Error('Method not implemented.')
103 onVideosHistoryChange () {
104 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
107 const message = this.videosHistoryEnabled === true ?
108 $localize`Videos history is enabled` :
109 $localize`Videos history is disabled`
111 this.notifier.success(message)
113 this.authService.refreshUserInformation()
116 err => this.notifier.error(err.message)
120 async deleteHistory () {
121 const title = $localize`Delete videos history`
122 const message = $localize`Are you sure you want to delete all your videos history?`
124 const res = await this.confirmService.confirm(message, title)
125 if (res !== true) return
127 this.userHistoryService.deleteUserVideosHistory()
130 this.notifier.success($localize`Videos history deleted`)
135 err => this.notifier.error(err.message)