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 selector: 'my-account-history',
19 templateUrl: './my-account-history.component.html',
20 styleUrls: [ './my-account-history.component.scss' ]
22 export class MyAccountHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy {
24 pagination: ComponentPagination = {
29 videosHistoryEnabled: boolean
32 protected router: Router,
33 protected serverService: ServerService,
34 protected route: ActivatedRoute,
35 protected authService: AuthService,
36 protected userService: UserService,
37 protected notifier: Notifier,
38 protected screenService: ScreenService,
39 protected storageService: LocalStorageService,
40 private confirmService: ConfirmService,
41 private userHistoryService: UserHistoryService
45 this.titlePage = $localize`My videos history`
51 this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
58 getVideosObservable (page: number) {
59 const newPagination = immutableAssign(this.pagination, { currentPage: page })
61 return this.userHistoryService.getUserVideosHistory(newPagination)
64 generateSyndicationList () {
65 throw new Error('Method not implemented.')
68 onVideosHistoryChange () {
69 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
72 const message = this.videosHistoryEnabled === true ?
73 $localize`Videos history is enabled` :
74 $localize`Videos history is disabled`
76 this.notifier.success(message)
78 this.authService.refreshUserInformation()
81 err => this.notifier.error(err.message)
85 async deleteHistory () {
86 const title = $localize`Delete videos history`
87 const message = $localize`Are you sure you want to delete all your videos history?`
89 const res = await this.confirmService.confirm(message, title)
90 if (res !== true) return
92 this.userHistoryService.deleteUserVideosHistory()
95 this.notifier.success($localize`Videos history deleted`)
100 err => this.notifier.error(err.message)