1 import { tap } from 'rxjs/operators'
2 import { Component, ComponentFactoryResolver, OnInit, ViewChild } from '@angular/core'
3 import { ActivatedRoute, Router } from '@angular/router'
16 import { immutableAssign } from '@app/helpers'
17 import { UserHistoryService, Video } from '@app/shared/shared-main'
18 import { MiniatureDisplayOptions, VideosSelectionComponent } from '@app/shared/shared-video-miniature'
21 templateUrl: './my-history.component.html',
22 styleUrls: [ './my-history.component.scss' ]
24 export class MyHistoryComponent implements OnInit, DisableForReuseHook {
25 @ViewChild('videosSelection', { static: true }) videosSelection: VideosSelectionComponent
28 pagination: ComponentPagination = {
34 videosHistoryEnabled: boolean
36 miniatureDisplayOptions: MiniatureDisplayOptions = {
46 getVideosObservableFunction = this.getVideosObservable.bind(this)
54 protected router: Router,
55 protected serverService: ServerService,
56 protected route: ActivatedRoute,
57 protected authService: AuthService,
58 protected userService: UserService,
59 protected notifier: Notifier,
60 protected screenService: ScreenService,
61 protected storageService: LocalStorageService,
62 private confirmService: ConfirmService,
63 private userHistoryService: UserHistoryService,
64 protected cfr: ComponentFactoryResolver
66 this.titlePage = $localize`My watch history`
70 this.user = this.authService.getUser()
72 this.authService.userInformationLoaded
73 .subscribe(() => this.videosHistoryEnabled = this.user.videosHistoryEnabled)
77 this.videosSelection.disableForReuse()
81 this.videosSelection.enabledForReuse()
85 this.videosSelection.reloadVideos()
88 onSearch (search: string) {
93 getVideosObservable (page: number) {
94 const newPagination = immutableAssign(this.pagination, { currentPage: page })
96 return this.userHistoryService.getUserVideosHistory(newPagination, this.search)
98 tap(res => this.pagination.totalItems = res.total)
102 generateSyndicationList () {
103 /* method disabled */
104 throw new Error('Method not implemented.')
107 onVideosHistoryChange () {
108 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
111 const message = this.videosHistoryEnabled === true
112 ? $localize`Videos history is enabled`
113 : $localize`Videos history is disabled`
115 this.notifier.success(message)
117 this.authService.refreshUserInformation()
120 error: err => this.notifier.error(err.message)
124 async deleteHistory () {
125 const title = $localize`Delete videos history`
126 const message = $localize`Are you sure you want to delete all your videos history?`
128 const res = await this.confirmService.confirm(message, title)
129 if (res !== true) return
131 this.userHistoryService.deleteUserVideosHistory()
134 this.notifier.success($localize`Videos history deleted`)
139 error: err => this.notifier.error(err.message)