]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-library/my-video-playlists/my-video-playlists.component.ts
Add ability to redirect users on external auth
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / my-video-playlists / my-video-playlists.component.ts
CommitLineData
67ed6552 1import { Subject } from 'rxjs'
2e46eb97
C
2import { mergeMap } from 'rxjs/operators'
3import { Component } from '@angular/core'
4import { AuthService, ComponentPagination, ConfirmService, Notifier } from '@app/core'
67ed6552 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})
2e46eb97 12export class MyVideoPlaylistsComponent {
830b4faf
C
13 videoPlaylists: VideoPlaylist[] = []
14
15 pagination: ComponentPagination = {
16 currentPage: 1,
ad453580 17 itemsPerPage: 5,
830b4faf
C
18 totalItems: null
19 }
20
ad453580
C
21 onDataSubject = new Subject<any[]>()
22
2e46eb97 23 search: string
830b4faf
C
24
25 constructor (
26 private authService: AuthService,
27 private notifier: Notifier,
28 private confirmService: ConfirmService,
66357162 29 private videoPlaylistService: VideoPlaylistService
2e46eb97 30 ) {}
830b4faf
C
31
32 async deleteVideoPlaylist (videoPlaylist: VideoPlaylist) {
33 const res = await this.confirmService.confirm(
66357162
C
34 $localize`Do you really want to delete ${videoPlaylist.displayName}?`,
35 $localize`Delete`
830b4faf
C
36 )
37 if (res === false) return
38
39 this.videoPlaylistService.removeVideoPlaylist(videoPlaylist)
1378c0d3
C
40 .subscribe({
41 next: () => {
830b4faf
C
42 this.videoPlaylists = this.videoPlaylists
43 .filter(p => p.id !== videoPlaylist.id)
44
66357162 45 this.notifier.success($localize`Playlist ${videoPlaylist.displayName}} deleted.`)
830b4faf
C
46 },
47
1378c0d3
C
48 error: err => this.notifier.error(err.message)
49 })
830b4faf
C
50 }
51
52 isRegularPlaylist (playlist: VideoPlaylist) {
53 return playlist.type.id === VideoPlaylistType.REGULAR
54 }
55
f0a39880 56 onNearOfBottom () {
830b4faf
C
57 // Last page
58 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
59
60 this.pagination.currentPage += 1
61 this.loadVideoPlaylists()
62 }
f0a39880 63
2e46eb97
C
64 onSearch (search: string) {
65 this.search = search
66 this.loadVideoPlaylists(true)
bf64ed41
RK
67 }
68
9d45db29 69 private loadVideoPlaylists (reset = false) {
f0a39880 70 this.authService.userInformationLoaded
a02b93ce 71 .pipe(mergeMap(() => {
2e46eb97
C
72 const user = this.authService.getUser()
73
74 return this.videoPlaylistService.listAccountPlaylists(user.account, this.pagination, '-updatedAt', this.search)
75 })).subscribe(res => {
9d45db29 76 if (reset) this.videoPlaylists = []
2e46eb97 77
f0a39880
C
78 this.videoPlaylists = this.videoPlaylists.concat(res.data)
79 this.pagination.totalItems = res.total
ad453580
C
80
81 this.onDataSubject.next(res.data)
f0a39880
C
82 })
83 }
830b4faf 84}