diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-17 16:02:38 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-06-25 14:44:01 +0200 |
commit | 37a44fc915eef2140e22ceb96aba6b6eb2509007 (patch) | |
tree | dd4a370ecc96cf38c99b940261aadc27065da7ae /client/src/app/+search/shared | |
parent | 33eb19e5199cc9fa4d73c6675c97508e3e072ef9 (diff) | |
download | PeerTube-37a44fc915eef2140e22ceb96aba6b6eb2509007.tar.gz PeerTube-37a44fc915eef2140e22ceb96aba6b6eb2509007.tar.zst PeerTube-37a44fc915eef2140e22ceb96aba6b6eb2509007.zip |
Add ability to search playlists
Diffstat (limited to 'client/src/app/+search/shared')
5 files changed, 110 insertions, 0 deletions
diff --git a/client/src/app/+search/shared/abstract-lazy-load.resolver.ts b/client/src/app/+search/shared/abstract-lazy-load.resolver.ts new file mode 100644 index 000000000..31240f451 --- /dev/null +++ b/client/src/app/+search/shared/abstract-lazy-load.resolver.ts | |||
@@ -0,0 +1,34 @@ | |||
1 | import { Observable } from 'rxjs' | ||
2 | import { map } from 'rxjs/operators' | ||
3 | import { ActivatedRouteSnapshot, Resolve, Router } from '@angular/router' | ||
4 | import { ResultList } from '@shared/models/result-list.model' | ||
5 | |||
6 | export abstract class AbstractLazyLoadResolver <T> implements Resolve<any> { | ||
7 | protected router: Router | ||
8 | |||
9 | resolve (route: ActivatedRouteSnapshot) { | ||
10 | const url = route.params.url | ||
11 | |||
12 | if (!url) { | ||
13 | console.error('Could not find url param.', { params: route.params }) | ||
14 | return this.router.navigateByUrl('/404') | ||
15 | } | ||
16 | |||
17 | return this.finder(url) | ||
18 | .pipe( | ||
19 | map(result => { | ||
20 | if (result.data.length !== 1) { | ||
21 | console.error('Cannot find result for this URL') | ||
22 | return this.router.navigateByUrl('/404') | ||
23 | } | ||
24 | |||
25 | const redirectUrl = this.buildUrl(result.data[0]) | ||
26 | |||
27 | return this.router.navigateByUrl(redirectUrl) | ||
28 | }) | ||
29 | ) | ||
30 | } | ||
31 | |||
32 | protected abstract finder (url: string): Observable<ResultList<T>> | ||
33 | protected abstract buildUrl (e: T): string | ||
34 | } | ||
diff --git a/client/src/app/+search/shared/channel-lazy-load.resolver.ts b/client/src/app/+search/shared/channel-lazy-load.resolver.ts new file mode 100644 index 000000000..5e010f795 --- /dev/null +++ b/client/src/app/+search/shared/channel-lazy-load.resolver.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { Router } from '@angular/router' | ||
3 | import { VideoChannel } from '@app/shared/shared-main' | ||
4 | import { SearchService } from '@app/shared/shared-search' | ||
5 | import { AbstractLazyLoadResolver } from './abstract-lazy-load.resolver' | ||
6 | |||
7 | @Injectable() | ||
8 | export class ChannelLazyLoadResolver extends AbstractLazyLoadResolver<VideoChannel> { | ||
9 | |||
10 | constructor ( | ||
11 | protected router: Router, | ||
12 | private searchService: SearchService | ||
13 | ) { | ||
14 | super() | ||
15 | } | ||
16 | |||
17 | protected finder (url: string) { | ||
18 | return this.searchService.searchVideoChannels({ search: url }) | ||
19 | } | ||
20 | |||
21 | protected buildUrl (channel: VideoChannel) { | ||
22 | return '/video-channels/' + channel.nameWithHost | ||
23 | } | ||
24 | } | ||
diff --git a/client/src/app/+search/shared/index.ts b/client/src/app/+search/shared/index.ts new file mode 100644 index 000000000..1e68989ae --- /dev/null +++ b/client/src/app/+search/shared/index.ts | |||
@@ -0,0 +1,4 @@ | |||
1 | export * from './abstract-lazy-load.resolver' | ||
2 | export * from './channel-lazy-load.resolver' | ||
3 | export * from './playlist-lazy-load.resolver' | ||
4 | export * from './video-lazy-load.resolver' | ||
diff --git a/client/src/app/+search/shared/playlist-lazy-load.resolver.ts b/client/src/app/+search/shared/playlist-lazy-load.resolver.ts new file mode 100644 index 000000000..14ae798df --- /dev/null +++ b/client/src/app/+search/shared/playlist-lazy-load.resolver.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { Router } from '@angular/router' | ||
3 | import { SearchService } from '@app/shared/shared-search' | ||
4 | import { VideoPlaylist } from '@app/shared/shared-video-playlist' | ||
5 | import { AbstractLazyLoadResolver } from './abstract-lazy-load.resolver' | ||
6 | |||
7 | @Injectable() | ||
8 | export class PlaylistLazyLoadResolver extends AbstractLazyLoadResolver<VideoPlaylist> { | ||
9 | |||
10 | constructor ( | ||
11 | protected router: Router, | ||
12 | private searchService: SearchService | ||
13 | ) { | ||
14 | super() | ||
15 | } | ||
16 | |||
17 | protected finder (url: string) { | ||
18 | return this.searchService.searchVideoPlaylists({ search: url }) | ||
19 | } | ||
20 | |||
21 | protected buildUrl (playlist: VideoPlaylist) { | ||
22 | return '/w/p/' + playlist.uuid | ||
23 | } | ||
24 | } | ||
diff --git a/client/src/app/+search/shared/video-lazy-load.resolver.ts b/client/src/app/+search/shared/video-lazy-load.resolver.ts new file mode 100644 index 000000000..12b5b2e82 --- /dev/null +++ b/client/src/app/+search/shared/video-lazy-load.resolver.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { Router } from '@angular/router' | ||
3 | import { Video } from '@app/shared/shared-main' | ||
4 | import { SearchService } from '@app/shared/shared-search' | ||
5 | import { AbstractLazyLoadResolver } from './abstract-lazy-load.resolver' | ||
6 | |||
7 | @Injectable() | ||
8 | export class VideoLazyLoadResolver extends AbstractLazyLoadResolver<Video> { | ||
9 | |||
10 | constructor ( | ||
11 | protected router: Router, | ||
12 | private searchService: SearchService | ||
13 | ) { | ||
14 | super() | ||
15 | } | ||
16 | |||
17 | protected finder (url: string) { | ||
18 | return this.searchService.searchVideos({ search: url }) | ||
19 | } | ||
20 | |||
21 | protected buildUrl (video: Video) { | ||
22 | return '/w/' + video.uuid | ||
23 | } | ||
24 | } | ||