]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-library/my-history/my-history.component.ts
Fix rss feed with HLS videos
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / my-history / my-history.component.ts
CommitLineData
80bfd33c
C
1import { Component, OnDestroy, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router'
67ed6552
C
3import {
4 AuthService,
5 ComponentPagination,
6 ConfirmService,
7 LocalStorageService,
8 Notifier,
9 ScreenService,
10 ServerService,
11 UserService
12} from '@app/core'
13import { immutableAssign } from '@app/helpers'
14import { UserHistoryService } from '@app/shared/shared-main'
15import { AbstractVideoList } from '@app/shared/shared-video-miniature'
d8b34ee5
RK
16import { Subject } from 'rxjs'
17import { debounceTime, tap, distinctUntilChanged } from 'rxjs/operators'
80bfd33c
C
18
19@Component({
17119e4a
C
20 templateUrl: './my-history.component.html',
21 styleUrls: [ './my-history.component.scss' ]
80bfd33c 22})
17119e4a 23export class MyHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy {
80bfd33c 24 titlePage: string
80bfd33c
C
25 pagination: ComponentPagination = {
26 currentPage: 1,
27 itemsPerPage: 5,
28 totalItems: null
29 }
276d9652 30 videosHistoryEnabled: boolean
d8b34ee5
RK
31 search: string
32
33 protected searchStream: Subject<string>
80bfd33c 34
80bfd33c
C
35 constructor (
36 protected router: Router,
489290b8 37 protected serverService: ServerService,
80bfd33c
C
38 protected route: ActivatedRoute,
39 protected authService: AuthService,
276d9652 40 protected userService: UserService,
f8b2c1b4 41 protected notifier: Notifier,
80bfd33c 42 protected screenService: ScreenService,
d3217560 43 protected storageService: LocalStorageService,
80bfd33c 44 private confirmService: ConfirmService,
80bfd33c
C
45 private userHistoryService: UserHistoryService
46 ) {
47 super()
48
d8b34ee5 49 this.titlePage = $localize`My watch history`
80bfd33c
C
50 }
51
52 ngOnInit () {
53 super.ngOnInit()
276d9652 54
4f926722
C
55 this.authService.userInformationLoaded
56 .subscribe(() => {
57 this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
58 })
59
d8b34ee5
RK
60 this.searchStream = new Subject()
61
62 this.searchStream
63 .pipe(
64 debounceTime(400),
65 distinctUntilChanged()
66 )
67 .subscribe(search => {
68 this.search = search
69 this.reloadVideos()
70 })
71 }
72
73 onSearch (event: Event) {
74 const target = event.target as HTMLInputElement
75 this.searchStream.next(target.value)
76 }
77
78 resetSearch () {
79 const searchInput = document.getElementById('history-search') as HTMLInputElement
80 searchInput.value = ''
81 this.searchStream.next('')
80bfd33c
C
82 }
83
84 ngOnDestroy () {
85 super.ngOnDestroy()
86 }
87
88 getVideosObservable (page: number) {
89 const newPagination = immutableAssign(this.pagination, { currentPage: page })
90
d8b34ee5
RK
91 return this.userHistoryService.getUserVideosHistory(newPagination, this.search)
92 .pipe(
93 tap(res => this.pagination.totalItems = res.total)
94 )
80bfd33c
C
95 }
96
97 generateSyndicationList () {
98 throw new Error('Method not implemented.')
99 }
276d9652
C
100
101 onVideosHistoryChange () {
102 this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
103 .subscribe(
104 () => {
105 const message = this.videosHistoryEnabled === true ?
66357162
C
106 $localize`Videos history is enabled` :
107 $localize`Videos history is disabled`
276d9652 108
f8b2c1b4 109 this.notifier.success(message)
276d9652
C
110
111 this.authService.refreshUserInformation()
112 },
113
f8b2c1b4 114 err => this.notifier.error(err.message)
276d9652
C
115 )
116 }
117
118 async deleteHistory () {
66357162
C
119 const title = $localize`Delete videos history`
120 const message = $localize`Are you sure you want to delete all your videos history?`
276d9652
C
121
122 const res = await this.confirmService.confirm(message, title)
123 if (res !== true) return
124
125 this.userHistoryService.deleteUserVideosHistory()
126 .subscribe(
127 () => {
66357162 128 this.notifier.success($localize`Videos history deleted`)
276d9652
C
129
130 this.reloadVideos()
131 },
132
f8b2c1b4 133 err => this.notifier.error(err.message)
276d9652
C
134 )
135 }
80bfd33c 136}