]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+videos/video-list/video-user-subscriptions.component.ts
Channel/account page redesign feedbacks
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / video-list / video-user-subscriptions.component.ts
1
2 import { switchMap } from 'rxjs/operators'
3 import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core'
4 import { ActivatedRoute, Router } from '@angular/router'
5 import { AuthService, LocalStorageService, Notifier, ScopedTokensService, ScreenService, ServerService, UserService } from '@app/core'
6 import { HooksService } from '@app/core/plugins/hooks.service'
7 import { immutableAssign } from '@app/helpers'
8 import { VideoService } from '@app/shared/shared-main'
9 import { UserSubscriptionService } from '@app/shared/shared-user-subscription'
10 import { AbstractVideoList } from '@app/shared/shared-video-miniature'
11 import { FeedFormat, VideoSortField } from '@shared/models'
12 import { environment } from '../../../environments/environment'
13 import { copyToClipboard } from '../../../root-helpers/utils'
14
15 @Component({
16 selector: 'my-videos-user-subscriptions',
17 styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ],
18 templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html'
19 })
20 export class VideoUserSubscriptionsComponent extends AbstractVideoList implements OnInit, OnDestroy {
21 titlePage: string
22 sort = '-publishedAt' as VideoSortField
23 groupByDate = true
24
25 constructor (
26 protected router: Router,
27 protected serverService: ServerService,
28 protected route: ActivatedRoute,
29 protected notifier: Notifier,
30 protected authService: AuthService,
31 protected userService: UserService,
32 protected screenService: ScreenService,
33 protected storageService: LocalStorageService,
34 private userSubscription: UserSubscriptionService,
35 protected cfr: ComponentFactoryResolver,
36 private hooks: HooksService,
37 private videoService: VideoService,
38 private scopedTokensService: ScopedTokensService
39 ) {
40 super()
41
42 this.titlePage = $localize`Videos from your subscriptions`
43
44 this.actions.push({
45 routerLink: '/my-library/subscriptions',
46 label: $localize`Subscriptions`,
47 iconName: 'cog'
48 })
49 }
50
51 ngOnInit () {
52 super.ngOnInit()
53
54 const user = this.authService.getUser()
55 let feedUrl = environment.originServerUrl
56
57 this.authService.userInformationLoaded
58 .pipe(switchMap(() => this.scopedTokensService.getScopedTokens()))
59 .subscribe(
60 tokens => {
61 const feeds = this.videoService.getVideoSubscriptionFeedUrls(user.account.id, tokens.feedToken)
62 feedUrl = feedUrl + feeds.find(f => f.format === FeedFormat.RSS).url
63
64 this.actions.unshift({
65 label: $localize`Copy feed URL`,
66 iconName: 'syndication',
67 justIcon: true,
68 href: feedUrl,
69 click: e => {
70 e.preventDefault()
71 copyToClipboard(feedUrl)
72 this.activateCopiedMessage()
73 }
74 })
75 },
76
77 err => {
78 this.notifier.error(err.message)
79 }
80 )
81 }
82
83 ngOnDestroy () {
84 super.ngOnDestroy()
85 }
86
87 getVideosObservable (page: number) {
88 const newPagination = immutableAssign(this.pagination, { currentPage: page })
89 const params = {
90 videoPagination: newPagination,
91 sort: this.sort,
92 skipCount: true
93 }
94
95 return this.hooks.wrapObsFun(
96 this.userSubscription.getUserSubscriptionVideos.bind(this.userSubscription),
97 params,
98 'common',
99 'filter:api.user-subscriptions-videos.videos.list.params',
100 'filter:api.user-subscriptions-videos.videos.list.result'
101 )
102 }
103
104 generateSyndicationList () {
105 /* method disabled: the view provides its own */
106 throw new Error('Method not implemented.')
107 }
108
109 activateCopiedMessage () {
110 this.notifier.success($localize`Feed URL copied`)
111 }
112 }