1 import { Subject } from 'rxjs'
2 import { tap } from 'rxjs/operators'
3 import { Component, ComponentFactoryResolver, OnInit, ViewChild } from '@angular/core'
4 import { ActivatedRoute, Router } from '@angular/router'
17 import { immutableAssign } from '@app/helpers'
18 import { UserHistoryService, Video } from '@app/shared/shared-main'
19 import { MiniatureDisplayOptions, VideosSelectionComponent } from '@app/shared/shared-video-miniature'
22 templateUrl: './my-history.component.html',
23 styleUrls: [ './my-history.component.scss' ]
25 export class MyHistoryComponent implements OnInit, DisableForReuseHook {
26 @ViewChild('videosSelection', { static: true }) videosSelection: VideosSelectionComponent
29 pagination: ComponentPagination = {
35 videosHistoryEnabled: boolean
37 miniatureDisplayOptions: MiniatureDisplayOptions = {
47 getVideosObservableFunction = this.getVideosObservable.bind(this)
55 protected router: Router,
56 protected serverService: ServerService,
57 protected route: ActivatedRoute,
58 protected authService: AuthService,
59 protected userService: UserService,
60 protected notifier: Notifier,
61 protected screenService: ScreenService,
62 protected storageService: LocalStorageService,
63 private confirmService: ConfirmService,
64 private userHistoryService: UserHistoryService,
65 protected cfr: ComponentFactoryResolver
67 this.titlePage = $localize`My watch history`
71 this.user = this.authService.getUser()
73 this.authService.userInformationLoaded
74 .subscribe(() => this.videosHistoryEnabled = this.user.videosHistoryEnabled)
78 this.videosSelection.disableForReuse()
82 this.videosSelection.enabledForReuse()
86 this.videosSelection.reloadVideos()
89 onSearch (search: string) {
94 getVideosObservable (page: number) {
95 const newPagination = immutableAssign(this.pagination, { currentPage: page })
97 return this.userHistoryService.getUserVideosHistory(newPagination, this.search)
99 tap(res => this.pagination.totalItems = res.total)
103 generateSyndicationList () {
104 /* method disabled */
105 throw new Error('Method not implemented.')
108 onVideosHistoryChange () {
109 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
112 const message = this.videosHistoryEnabled === true ?
113 $localize`Videos history is enabled` :
114 $localize`Videos history is disabled`
116 this.notifier.success(message)
118 this.authService.refreshUserInformation()
121 err => this.notifier.error(err.message)
125 async deleteHistory () {
126 const title = $localize`Delete videos history`
127 const message = $localize`Are you sure you want to delete all your videos history?`
129 const res = await this.confirmService.confirm(message, title)
130 if (res !== true) return
132 this.userHistoryService.deleteUserVideosHistory()
135 this.notifier.success($localize`Videos history deleted`)
140 err => this.notifier.error(err.message)