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