]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-video-playlists/my-account-video-playlists.component.ts
Update build steps for localization
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-video-playlists / my-account-video-playlists.component.ts
CommitLineData
67ed6552 1import { Subject } from 'rxjs'
a02b93ce 2import { debounceTime, mergeMap } from 'rxjs/operators'
830b4faf 3import { Component, OnInit } from '@angular/core'
67ed6552
C
4import { AuthService, ComponentPagination, ConfirmService, Notifier, User } from '@app/core'
5import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist'
830b4faf 6import { I18n } from '@ngx-translate/i18n-polyfill'
830b4faf
C
7import { VideoPlaylistType } from '@shared/models'
8
9@Component({
10 selector: 'my-account-video-playlists',
11 templateUrl: './my-account-video-playlists.component.html',
12 styleUrls: [ './my-account-video-playlists.component.scss' ]
13})
14export class MyAccountVideoPlaylistsComponent implements OnInit {
bf64ed41 15 videoPlaylistsSearch: string
830b4faf 16 videoPlaylists: VideoPlaylist[] = []
bf64ed41 17 videoPlaylistSearchChanged = new Subject<string>()
830b4faf
C
18
19 pagination: ComponentPagination = {
20 currentPage: 1,
ad453580 21 itemsPerPage: 5,
830b4faf
C
22 totalItems: null
23 }
24
ad453580
C
25 onDataSubject = new Subject<any[]>()
26
830b4faf
C
27 private user: User
28
29 constructor (
30 private authService: AuthService,
31 private notifier: Notifier,
32 private confirmService: ConfirmService,
33 private videoPlaylistService: VideoPlaylistService,
34 private i18n: I18n
35 ) {}
36
37 ngOnInit () {
38 this.user = this.authService.getUser()
39
40 this.loadVideoPlaylists()
bf64ed41
RK
41
42 this.videoPlaylistSearchChanged
43 .pipe(
44 debounceTime(500))
45 .subscribe(() => {
9d45db29 46 this.loadVideoPlaylists(true)
bf64ed41 47 })
830b4faf
C
48 }
49
50 async deleteVideoPlaylist (videoPlaylist: VideoPlaylist) {
51 const res = await this.confirmService.confirm(
52 this.i18n(
53 'Do you really want to delete {{playlistDisplayName}}?',
54 { playlistDisplayName: videoPlaylist.displayName }
55 ),
56 this.i18n('Delete')
57 )
58 if (res === false) return
59
60 this.videoPlaylistService.removeVideoPlaylist(videoPlaylist)
61 .subscribe(
62 () => {
63 this.videoPlaylists = this.videoPlaylists
64 .filter(p => p.id !== videoPlaylist.id)
65
66 this.notifier.success(
67 this.i18n('Playlist {{playlistDisplayName}} deleted.', { playlistDisplayName: videoPlaylist.displayName })
68 )
69 },
70
71 error => this.notifier.error(error.message)
72 )
73 }
74
75 isRegularPlaylist (playlist: VideoPlaylist) {
76 return playlist.type.id === VideoPlaylistType.REGULAR
77 }
78
f0a39880 79 onNearOfBottom () {
830b4faf
C
80 // Last page
81 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
82
83 this.pagination.currentPage += 1
84 this.loadVideoPlaylists()
85 }
f0a39880 86
4f5d0459
RK
87 resetSearch () {
88 this.videoPlaylistsSearch = ''
89 this.onVideoPlaylistSearchChanged()
90 }
91
bf64ed41
RK
92 onVideoPlaylistSearchChanged () {
93 this.videoPlaylistSearchChanged.next()
94 }
95
9d45db29 96 private loadVideoPlaylists (reset = false) {
f0a39880 97 this.authService.userInformationLoaded
a02b93ce 98 .pipe(mergeMap(() => {
bf64ed41 99 return this.videoPlaylistService.listAccountPlaylists(this.user.account, this.pagination, '-updatedAt', this.videoPlaylistsSearch)
f3628e69 100 }))
f0a39880 101 .subscribe(res => {
9d45db29 102 if (reset) this.videoPlaylists = []
f0a39880
C
103 this.videoPlaylists = this.videoPlaylists.concat(res.data)
104 this.pagination.totalItems = res.total
ad453580
C
105
106 this.onDataSubject.next(res.data)
f0a39880
C
107 })
108 }
830b4faf 109}