]>
Commit | Line | Data |
---|---|---|
07f81d9d | 1 | import { forkJoin, Subscription } from 'rxjs' |
67ed6552 | 2 | import { first, tap } from 'rxjs/operators' |
5bcbcbe3 | 3 | import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core' |
0626e7af | 4 | import { ActivatedRoute, Router } from '@angular/router' |
67ed6552 C |
5 | import { AuthService, ConfirmService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' |
6 | import { immutableAssign } from '@app/helpers' | |
7 | import { Account, AccountService, VideoService } from '@app/shared/shared-main' | |
8 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' | |
0aa52e17 | 9 | import { VideoFilter } from '@shared/models' |
0626e7af C |
10 | |
11 | @Component({ | |
12 | selector: 'my-account-videos', | |
67ed6552 | 13 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html', |
0626e7af | 14 | styleUrls: [ |
ae2dd046 | 15 | '../../shared/shared-video-miniature/abstract-video-list.scss' |
0626e7af C |
16 | ] |
17 | }) | |
18 | export class AccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { | |
b1d40cff | 19 | titlePage: string |
0626e7af | 20 | loadOnInit = false |
07f81d9d | 21 | loadUserVideoPreferences = true |
0626e7af | 22 | |
0aa52e17 C |
23 | filter: VideoFilter = null |
24 | ||
0626e7af | 25 | private account: Account |
734a5ceb | 26 | private accountSub: Subscription |
0626e7af C |
27 | |
28 | constructor ( | |
29 | protected router: Router, | |
489290b8 | 30 | protected serverService: ServerService, |
0626e7af C |
31 | protected route: ActivatedRoute, |
32 | protected authService: AuthService, | |
d3217560 | 33 | protected userService: UserService, |
f8b2c1b4 | 34 | protected notifier: Notifier, |
0626e7af | 35 | protected confirmService: ConfirmService, |
bbe0f064 | 36 | protected screenService: ScreenService, |
d3217560 | 37 | protected storageService: LocalStorageService, |
0626e7af | 38 | private accountService: AccountService, |
5bcbcbe3 RK |
39 | private videoService: VideoService, |
40 | protected cfr: ComponentFactoryResolver | |
0626e7af C |
41 | ) { |
42 | super() | |
43 | } | |
44 | ||
45 | ngOnInit () { | |
46 | super.ngOnInit() | |
47 | ||
0aa52e17 C |
48 | this.enableAllFilterIfPossible() |
49 | ||
0626e7af | 50 | // Parent get the account for us |
07f81d9d C |
51 | this.accountSub = forkJoin([ |
52 | this.accountService.accountLoaded.pipe(first()), | |
53 | this.onUserLoadedSubject.pipe(first()) | |
54 | ]).subscribe(([ account ]) => { | |
55 | this.account = account | |
0626e7af | 56 | |
07f81d9d C |
57 | this.reloadVideos() |
58 | this.generateSyndicationList() | |
59 | }) | |
0626e7af C |
60 | } |
61 | ||
62 | ngOnDestroy () { | |
734a5ceb C |
63 | if (this.accountSub) this.accountSub.unsubscribe() |
64 | ||
0626e7af C |
65 | super.ngOnDestroy() |
66 | } | |
67 | ||
68 | getVideosObservable (page: number) { | |
69 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
0aa52e17 C |
70 | const options = { |
71 | account: this.account, | |
72 | videoPagination: newPagination, | |
73 | sort: this.sort, | |
74 | nsfwPolicy: this.nsfwPolicy, | |
75 | videoFilter: this.filter | |
76 | } | |
0626e7af | 77 | |
0bf1f265 | 78 | return this.videoService |
0aa52e17 | 79 | .getAccountVideos(options) |
b1d40cff | 80 | .pipe( |
93cae479 | 81 | tap(({ total }) => { |
66357162 | 82 | this.titlePage = $localize`Published ${total} videos` |
b1d40cff C |
83 | }) |
84 | ) | |
0626e7af C |
85 | } |
86 | ||
0aa52e17 C |
87 | toggleModerationDisplay () { |
88 | this.filter = this.buildLocalFilter(this.filter, null) | |
89 | ||
90 | this.reloadVideos() | |
91 | } | |
92 | ||
0626e7af C |
93 | generateSyndicationList () { |
94 | this.syndicationItems = this.videoService.getAccountFeedUrls(this.account.id) | |
95 | } | |
4d5e572f C |
96 | |
97 | displayAsRow () { | |
98 | return this.screenService.isInMobileView() | |
99 | } | |
0626e7af | 100 | } |