1 import { tap } from 'rxjs/operators'
2 import { Component, OnInit, ViewChild } from '@angular/core'
3 import { AuthService, ComponentPagination, ConfirmService, DisableForReuseHook, Notifier, User, UserService } from '@app/core'
4 import { immutableAssign } from '@app/helpers'
5 import { UserHistoryService, Video } from '@app/shared/shared-main'
6 import { MiniatureDisplayOptions, VideosSelectionComponent } from '@app/shared/shared-video-miniature'
9 templateUrl: './my-history.component.html',
10 styleUrls: [ './my-history.component.scss' ]
12 export class MyHistoryComponent implements OnInit, DisableForReuseHook {
13 @ViewChild('videosSelection', { static: true }) videosSelection: VideosSelectionComponent
16 pagination: ComponentPagination = {
22 videosHistoryEnabled: boolean
24 miniatureDisplayOptions: MiniatureDisplayOptions = {
34 getVideosObservableFunction = this.getVideosObservable.bind(this)
44 private authService: AuthService,
45 private userService: UserService,
46 private notifier: Notifier,
47 private confirmService: ConfirmService,
48 private userHistoryService: UserHistoryService
50 this.titlePage = $localize`My watch history`
54 this.user = this.authService.getUser()
56 this.authService.userInformationLoaded
57 .subscribe(() => this.videosHistoryEnabled = this.user.videosHistoryEnabled)
69 this.videosSelection.reloadVideos()
72 onSearch (search: string) {
77 getVideosObservable (page: number) {
78 const newPagination = immutableAssign(this.pagination, { currentPage: page })
80 return this.userHistoryService.list(newPagination, this.search)
82 tap(res => this.pagination.totalItems = res.total)
86 generateSyndicationList () {
88 throw new Error('Method not implemented.')
91 onVideosHistoryChange () {
92 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
95 const message = this.videosHistoryEnabled === true
96 ? $localize`Video history is enabled`
97 : $localize`Video history is disabled`
99 this.notifier.success(message)
101 this.authService.refreshUserInformation()
104 error: err => this.notifier.error(err.message)
108 deleteHistoryElement (video: Video) {
109 this.userHistoryService.deleteElement(video)
112 this.videos = this.videos.filter(v => v.id !== video.id)
115 error: err => this.notifier.error(err.message)
119 async clearAllHistory () {
120 const title = $localize`Delete video history`
121 const message = $localize`Are you sure you want to delete all your video history?`
123 const res = await this.confirmService.confirm(message, title)
124 if (res !== true) return
126 this.userHistoryService.clearAll()
129 this.notifier.success($localize`Video history deleted`)
134 error: err => this.notifier.error(err.message)