diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2021-01-19 13:43:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-19 13:43:33 +0100 |
commit | 370240824e2fb28b314255f6c23f5ea7d6b08625 (patch) | |
tree | 6d4350fd93ea0b960bd278a948cecbdfbd2b67d7 /client/src/app/+accounts/account-search/account-search.component.ts | |
parent | 2264c1ceedcf27998108b8f8b706e51ed910d4fb (diff) | |
download | PeerTube-370240824e2fb28b314255f6c23f5ea7d6b08625.tar.gz PeerTube-370240824e2fb28b314255f6c23f5ea7d6b08625.tar.zst PeerTube-370240824e2fb28b314255f6c23f5ea7d6b08625.zip |
Allow users/visitors to search through an account's videos (#3589)
* WIP: account search
* add search to account view
* add tests for account search
Diffstat (limited to 'client/src/app/+accounts/account-search/account-search.component.ts')
-rw-r--r-- | client/src/app/+accounts/account-search/account-search.component.ts | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/client/src/app/+accounts/account-search/account-search.component.ts b/client/src/app/+accounts/account-search/account-search.component.ts new file mode 100644 index 000000000..10c7a12d8 --- /dev/null +++ b/client/src/app/+accounts/account-search/account-search.component.ts | |||
@@ -0,0 +1,104 @@ | |||
1 | import { Subscription } from 'rxjs' | ||
2 | import { first, tap } from 'rxjs/operators' | ||
3 | import { Component, OnDestroy, OnInit } from '@angular/core' | ||
4 | import { ActivatedRoute, Router } from '@angular/router' | ||
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' | ||
9 | import { VideoFilter } from '@shared/models' | ||
10 | |||
11 | @Component({ | ||
12 | selector: 'my-account-search', | ||
13 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html', | ||
14 | styleUrls: [ | ||
15 | '../../shared/shared-video-miniature/abstract-video-list.scss' | ||
16 | ] | ||
17 | }) | ||
18 | export class AccountSearchComponent extends AbstractVideoList implements OnInit, OnDestroy { | ||
19 | titlePage: string | ||
20 | loadOnInit = false | ||
21 | |||
22 | search = '' | ||
23 | filter: VideoFilter = null | ||
24 | |||
25 | private account: Account | ||
26 | private accountSub: Subscription | ||
27 | |||
28 | constructor ( | ||
29 | protected router: Router, | ||
30 | protected serverService: ServerService, | ||
31 | protected route: ActivatedRoute, | ||
32 | protected authService: AuthService, | ||
33 | protected userService: UserService, | ||
34 | protected notifier: Notifier, | ||
35 | protected confirmService: ConfirmService, | ||
36 | protected screenService: ScreenService, | ||
37 | protected storageService: LocalStorageService, | ||
38 | private accountService: AccountService, | ||
39 | private videoService: VideoService | ||
40 | ) { | ||
41 | super() | ||
42 | } | ||
43 | |||
44 | ngOnInit () { | ||
45 | super.ngOnInit() | ||
46 | |||
47 | this.enableAllFilterIfPossible() | ||
48 | |||
49 | // Parent get the account for us | ||
50 | this.accountSub = this.accountService.accountLoaded | ||
51 | .pipe(first()) | ||
52 | .subscribe(account => { | ||
53 | this.account = account | ||
54 | |||
55 | this.reloadVideos() | ||
56 | this.generateSyndicationList() | ||
57 | }) | ||
58 | } | ||
59 | |||
60 | ngOnDestroy () { | ||
61 | if (this.accountSub) this.accountSub.unsubscribe() | ||
62 | |||
63 | super.ngOnDestroy() | ||
64 | } | ||
65 | |||
66 | updateSearch (value: string) { | ||
67 | if (value === '') this.router.navigate(['../videos'], { relativeTo: this.route }) | ||
68 | this.search = value | ||
69 | |||
70 | this.reloadVideos() | ||
71 | } | ||
72 | |||
73 | getVideosObservable (page: number) { | ||
74 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | ||
75 | const options = { | ||
76 | account: this.account, | ||
77 | videoPagination: newPagination, | ||
78 | sort: this.sort, | ||
79 | nsfwPolicy: this.nsfwPolicy, | ||
80 | videoFilter: this.filter, | ||
81 | search: this.search | ||
82 | } | ||
83 | |||
84 | return this.videoService | ||
85 | .getAccountVideos(options) | ||
86 | .pipe( | ||
87 | tap(({ total }) => { | ||
88 | this.titlePage = this.search | ||
89 | ? $localize`Published ${total} videos matching "${this.search}"` | ||
90 | : $localize`Published ${total} videos` | ||
91 | }) | ||
92 | ) | ||
93 | } | ||
94 | |||
95 | toggleModerationDisplay () { | ||
96 | this.filter = this.buildLocalFilter(this.filter, null) | ||
97 | |||
98 | this.reloadVideos() | ||
99 | } | ||
100 | |||
101 | generateSyndicationList () { | ||
102 | /* disable syndication */ | ||
103 | } | ||
104 | } | ||