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)
56 protected router: Router,
57 protected serverService: ServerService,
58 protected route: ActivatedRoute,
59 protected authService: AuthService,
60 protected userService: UserService,
61 protected notifier: Notifier,
62 protected screenService: ScreenService,
63 protected storageService: LocalStorageService,
64 private confirmService: ConfirmService,
65 private userHistoryService: UserHistoryService,
66 protected cfr: ComponentFactoryResolver
68 this.titlePage = $localize`My watch history`
72 this.user = this.authService.getUser()
74 this.authService.userInformationLoaded
75 .subscribe(() => this.videosHistoryEnabled = this.user.videosHistoryEnabled)
87 this.videosSelection.reloadVideos()
90 onSearch (search: string) {
95 getVideosObservable (page: number) {
96 const newPagination = immutableAssign(this.pagination, { currentPage: page })
98 return this.userHistoryService.getUserVideosHistory(newPagination, this.search)
100 tap(res => this.pagination.totalItems = res.total)
104 generateSyndicationList () {
105 /* method disabled */
106 throw new Error('Method not implemented.')
109 onVideosHistoryChange () {
110 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
113 const message = this.videosHistoryEnabled === true
114 ? $localize`Videos history is enabled`
115 : $localize`Videos history is disabled`
117 this.notifier.success(message)
119 this.authService.refreshUserInformation()
122 error: err => this.notifier.error(err.message)
126 async deleteHistory () {
127 const title = $localize`Delete videos history`
128 const message = $localize`Are you sure you want to delete all your videos history?`
130 const res = await this.confirmService.confirm(message, title)
131 if (res !== true) return
133 this.userHistoryService.deleteUserVideosHistory()
136 this.notifier.success($localize`Videos history deleted`)
141 error: err => this.notifier.error(err.message)