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'
18 templateUrl: './my-history.component.html',
19 styleUrls: [ './my-history.component.scss' ]
21 export class MyHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy {
23 pagination: ComponentPagination = {
28 videosHistoryEnabled: boolean
31 protected router: Router,
32 protected serverService: ServerService,
33 protected route: ActivatedRoute,
34 protected authService: AuthService,
35 protected userService: UserService,
36 protected notifier: Notifier,
37 protected screenService: ScreenService,
38 protected storageService: LocalStorageService,
39 private confirmService: ConfirmService,
40 private userHistoryService: UserHistoryService
44 this.titlePage = $localize`My videos history`
50 this.authService.userInformationLoaded
52 this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
61 getVideosObservable (page: number) {
62 const newPagination = immutableAssign(this.pagination, { currentPage: page })
64 return this.userHistoryService.getUserVideosHistory(newPagination)
67 generateSyndicationList () {
68 throw new Error('Method not implemented.')
71 onVideosHistoryChange () {
72 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
75 const message = this.videosHistoryEnabled === true ?
76 $localize`Videos history is enabled` :
77 $localize`Videos history is disabled`
79 this.notifier.success(message)
81 this.authService.refreshUserInformation()
84 err => this.notifier.error(err.message)
88 async deleteHistory () {
89 const title = $localize`Delete videos history`
90 const message = $localize`Are you sure you want to delete all your videos history?`
92 const res = await this.confirmService.confirm(message, title)
93 if (res !== true) return
95 this.userHistoryService.deleteUserVideosHistory()
98 this.notifier.success($localize`Videos history deleted`)
103 err => this.notifier.error(err.message)