]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+accounts/account-search/account-search.component.ts
modularize abstract video list header and implement video hotness recommendation...
[github/Chocobozzz/PeerTube.git] / client / src / app / +accounts / account-search / account-search.component.ts
CommitLineData
37024082
RK
1import { Subscription } from 'rxjs'
2import { first, tap } from 'rxjs/operators'
5bcbcbe3 3import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core'
37024082
RK
4import { ActivatedRoute, Router } from '@angular/router'
5import { AuthService, ConfirmService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core'
6import { immutableAssign } from '@app/helpers'
7import { Account, AccountService, VideoService } from '@app/shared/shared-main'
8import { AbstractVideoList } from '@app/shared/shared-video-miniature'
9import { VideoFilter } from '@shared/models'
10
11@Component({
12 selector: 'my-account-search',
13 templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html',
5bcbcbe3 14 styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ]
37024082
RK
15})
16export class AccountSearchComponent extends AbstractVideoList implements OnInit, OnDestroy {
17 titlePage: string
18 loadOnInit = false
19
20 search = ''
21 filter: VideoFilter = null
22
23 private account: Account
24 private accountSub: Subscription
25
26 constructor (
27 protected router: Router,
28 protected serverService: ServerService,
29 protected route: ActivatedRoute,
30 protected authService: AuthService,
31 protected userService: UserService,
32 protected notifier: Notifier,
33 protected confirmService: ConfirmService,
34 protected screenService: ScreenService,
35 protected storageService: LocalStorageService,
5bcbcbe3 36 protected cfr: ComponentFactoryResolver,
37024082
RK
37 private accountService: AccountService,
38 private videoService: VideoService
39 ) {
40 super()
41 }
42
43 ngOnInit () {
44 super.ngOnInit()
45
46 this.enableAllFilterIfPossible()
47
48 // Parent get the account for us
49 this.accountSub = this.accountService.accountLoaded
50 .pipe(first())
51 .subscribe(account => {
52 this.account = account
53
54 this.reloadVideos()
55 this.generateSyndicationList()
56 })
57 }
58
59 ngOnDestroy () {
60 if (this.accountSub) this.accountSub.unsubscribe()
61
62 super.ngOnDestroy()
63 }
64
65 updateSearch (value: string) {
66 if (value === '') this.router.navigate(['../videos'], { relativeTo: this.route })
67 this.search = value
68
69 this.reloadVideos()
70 }
71
72 getVideosObservable (page: number) {
73 const newPagination = immutableAssign(this.pagination, { currentPage: page })
74 const options = {
75 account: this.account,
76 videoPagination: newPagination,
77 sort: this.sort,
78 nsfwPolicy: this.nsfwPolicy,
79 videoFilter: this.filter,
80 search: this.search
81 }
82
83 return this.videoService
84 .getAccountVideos(options)
85 .pipe(
86 tap(({ total }) => {
87 this.titlePage = this.search
88 ? $localize`Published ${total} videos matching "${this.search}"`
89 : $localize`Published ${total} videos`
90 })
91 )
92 }
93
94 toggleModerationDisplay () {
95 this.filter = this.buildLocalFilter(this.filter, null)
96
97 this.reloadVideos()
98 }
99
100 generateSyndicationList () {
5bcbcbe3
RK
101 /* method disabled */
102 throw new Error('Method not implemented.')
37024082
RK
103 }
104}