1 import { Component, 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
49 this.titlePage = $localize`My watch history`
55 this.authService.userInformationLoaded
57 this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
60 this.searchStream = new Subject()
65 distinctUntilChanged()
67 .subscribe(search => {
73 onSearch (event: Event) {
74 const target = event.target as HTMLInputElement
75 this.searchStream.next(target.value)
79 const searchInput = document.getElementById('history-search') as HTMLInputElement
80 searchInput.value = ''
81 this.searchStream.next('')
88 getVideosObservable (page: number) {
89 const newPagination = immutableAssign(this.pagination, { currentPage: page })
91 return this.userHistoryService.getUserVideosHistory(newPagination, this.search)
93 tap(res => this.pagination.totalItems = res.total)
97 generateSyndicationList () {
98 throw new Error('Method not implemented.')
101 onVideosHistoryChange () {
102 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
105 const message = this.videosHistoryEnabled === true ?
106 $localize`Videos history is enabled` :
107 $localize`Videos history is disabled`
109 this.notifier.success(message)
111 this.authService.refreshUserInformation()
114 err => this.notifier.error(err.message)
118 async deleteHistory () {
119 const title = $localize`Delete videos history`
120 const message = $localize`Are you sure you want to delete all your videos history?`
122 const res = await this.confirmService.confirm(message, title)
123 if (res !== true) return
125 this.userHistoryService.deleteUserVideosHistory()
128 this.notifier.success($localize`Videos history deleted`)
133 err => this.notifier.error(err.message)