diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-19 09:24:29 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-25 11:24:11 +0200 |
commit | dd24f1bb0a4b252e5342b251ba36853364da7b8e (patch) | |
tree | 41a9506d07413f056fb90425705e258f96fdc77d /client/src/app/shared/shared-video-miniature/videos-selection.component.ts | |
parent | 2e80d256cc75b4b02c8efc3d3e4cdf57ddf401a8 (diff) | |
download | PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.gz PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.zst PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.zip |
Add video filters to common video pages
Diffstat (limited to 'client/src/app/shared/shared-video-miniature/videos-selection.component.ts')
-rw-r--r-- | client/src/app/shared/shared-video-miniature/videos-selection.component.ts | 106 |
1 files changed, 64 insertions, 42 deletions
diff --git a/client/src/app/shared/shared-video-miniature/videos-selection.component.ts b/client/src/app/shared/shared-video-miniature/videos-selection.component.ts index 456b36926..cafaf6e85 100644 --- a/client/src/app/shared/shared-video-miniature/videos-selection.component.ts +++ b/client/src/app/shared/shared-video-miniature/videos-selection.component.ts | |||
@@ -1,22 +1,8 @@ | |||
1 | import { Observable } from 'rxjs' | 1 | import { Observable, Subject } from 'rxjs' |
2 | import { | 2 | import { AfterContentInit, Component, ContentChildren, EventEmitter, Input, Output, QueryList, TemplateRef } from '@angular/core' |
3 | AfterContentInit, | 3 | import { ComponentPagination, Notifier, User } from '@app/core' |
4 | Component, | ||
5 | ComponentFactoryResolver, | ||
6 | ContentChildren, | ||
7 | EventEmitter, | ||
8 | Input, | ||
9 | OnDestroy, | ||
10 | OnInit, | ||
11 | Output, | ||
12 | QueryList, | ||
13 | TemplateRef | ||
14 | } from '@angular/core' | ||
15 | import { ActivatedRoute, Router } from '@angular/router' | ||
16 | import { AuthService, ComponentPagination, LocalStorageService, Notifier, ScreenService, ServerService, User, UserService } from '@app/core' | ||
17 | import { ResultList, VideoSortField } from '@shared/models' | 4 | import { ResultList, VideoSortField } from '@shared/models' |
18 | import { PeerTubeTemplateDirective, Video } from '../shared-main' | 5 | import { PeerTubeTemplateDirective, Video } from '../shared-main' |
19 | import { AbstractVideoList } from './abstract-video-list' | ||
20 | import { MiniatureDisplayOptions } from './video-miniature.component' | 6 | import { MiniatureDisplayOptions } from './video-miniature.component' |
21 | 7 | ||
22 | export type SelectionType = { [ id: number ]: boolean } | 8 | export type SelectionType = { [ id: number ]: boolean } |
@@ -26,14 +12,18 @@ export type SelectionType = { [ id: number ]: boolean } | |||
26 | templateUrl: './videos-selection.component.html', | 12 | templateUrl: './videos-selection.component.html', |
27 | styleUrls: [ './videos-selection.component.scss' ] | 13 | styleUrls: [ './videos-selection.component.scss' ] |
28 | }) | 14 | }) |
29 | export class VideosSelectionComponent extends AbstractVideoList implements OnInit, OnDestroy, AfterContentInit { | 15 | export class VideosSelectionComponent implements AfterContentInit { |
30 | @Input() user: User | 16 | @Input() user: User |
31 | @Input() pagination: ComponentPagination | 17 | @Input() pagination: ComponentPagination |
18 | |||
32 | @Input() titlePage: string | 19 | @Input() titlePage: string |
20 | |||
33 | @Input() miniatureDisplayOptions: MiniatureDisplayOptions | 21 | @Input() miniatureDisplayOptions: MiniatureDisplayOptions |
22 | |||
34 | @Input() noResultMessage = $localize`No results.` | 23 | @Input() noResultMessage = $localize`No results.` |
35 | @Input() enableSelection = true | 24 | @Input() enableSelection = true |
36 | @Input() loadOnInit = true | 25 | |
26 | @Input() disabled = false | ||
37 | 27 | ||
38 | @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<ResultList<Video>> | 28 | @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<ResultList<Video>> |
39 | 29 | ||
@@ -47,19 +37,18 @@ export class VideosSelectionComponent extends AbstractVideoList implements OnIni | |||
47 | rowButtonsTemplate: TemplateRef<any> | 37 | rowButtonsTemplate: TemplateRef<any> |
48 | globalButtonsTemplate: TemplateRef<any> | 38 | globalButtonsTemplate: TemplateRef<any> |
49 | 39 | ||
40 | videos: Video[] = [] | ||
41 | sort: VideoSortField = '-publishedAt' | ||
42 | |||
43 | onDataSubject = new Subject<any[]>() | ||
44 | |||
45 | hasDoneFirstQuery = false | ||
46 | |||
47 | private lastQueryLength: number | ||
48 | |||
50 | constructor ( | 49 | constructor ( |
51 | protected router: Router, | 50 | private notifier: Notifier |
52 | protected route: ActivatedRoute, | 51 | ) { } |
53 | protected notifier: Notifier, | ||
54 | protected authService: AuthService, | ||
55 | protected userService: UserService, | ||
56 | protected screenService: ScreenService, | ||
57 | protected storageService: LocalStorageService, | ||
58 | protected serverService: ServerService, | ||
59 | protected cfr: ComponentFactoryResolver | ||
60 | ) { | ||
61 | super() | ||
62 | } | ||
63 | 52 | ||
64 | @Input() get selection () { | 53 | @Input() get selection () { |
65 | return this._selection | 54 | return this._selection |
@@ -79,10 +68,6 @@ export class VideosSelectionComponent extends AbstractVideoList implements OnIni | |||
79 | this.videosModelChange.emit(this.videos) | 68 | this.videosModelChange.emit(this.videos) |
80 | } | 69 | } |
81 | 70 | ||
82 | ngOnInit () { | ||
83 | super.ngOnInit() | ||
84 | } | ||
85 | |||
86 | ngAfterContentInit () { | 71 | ngAfterContentInit () { |
87 | { | 72 | { |
88 | const t = this.templates.find(t => t.name === 'rowButtons') | 73 | const t = this.templates.find(t => t.name === 'rowButtons') |
@@ -93,10 +78,8 @@ export class VideosSelectionComponent extends AbstractVideoList implements OnIni | |||
93 | const t = this.templates.find(t => t.name === 'globalButtons') | 78 | const t = this.templates.find(t => t.name === 'globalButtons') |
94 | if (t) this.globalButtonsTemplate = t.template | 79 | if (t) this.globalButtonsTemplate = t.template |
95 | } | 80 | } |
96 | } | ||
97 | 81 | ||
98 | ngOnDestroy () { | 82 | this.loadMoreVideos() |
99 | super.ngOnDestroy() | ||
100 | } | 83 | } |
101 | 84 | ||
102 | getVideosObservable (page: number) { | 85 | getVideosObservable (page: number) { |
@@ -111,11 +94,50 @@ export class VideosSelectionComponent extends AbstractVideoList implements OnIni | |||
111 | return Object.keys(this._selection).some(k => this._selection[k] === true) | 94 | return Object.keys(this._selection).some(k => this._selection[k] === true) |
112 | } | 95 | } |
113 | 96 | ||
114 | generateSyndicationList () { | 97 | videoById (index: number, video: Video) { |
115 | throw new Error('Method not implemented.') | 98 | return video.id |
99 | } | ||
100 | |||
101 | onNearOfBottom () { | ||
102 | if (this.disabled) return | ||
103 | |||
104 | // No more results | ||
105 | if (this.lastQueryLength !== undefined && this.lastQueryLength < this.pagination.itemsPerPage) return | ||
106 | |||
107 | this.pagination.currentPage += 1 | ||
108 | |||
109 | this.loadMoreVideos() | ||
110 | } | ||
111 | |||
112 | loadMoreVideos (reset = false) { | ||
113 | this.getVideosObservable(this.pagination.currentPage) | ||
114 | .subscribe({ | ||
115 | next: ({ data }) => { | ||
116 | this.hasDoneFirstQuery = true | ||
117 | this.lastQueryLength = data.length | ||
118 | |||
119 | if (reset) this.videos = [] | ||
120 | this.videos = this.videos.concat(data) | ||
121 | this.videosModel = this.videos | ||
122 | |||
123 | this.onDataSubject.next(data) | ||
124 | }, | ||
125 | |||
126 | error: err => { | ||
127 | const message = $localize`Cannot load more videos. Try again later.` | ||
128 | |||
129 | console.error(message, { err }) | ||
130 | this.notifier.error(message) | ||
131 | } | ||
132 | }) | ||
133 | } | ||
134 | |||
135 | reloadVideos () { | ||
136 | this.pagination.currentPage = 1 | ||
137 | this.loadMoreVideos(true) | ||
116 | } | 138 | } |
117 | 139 | ||
118 | protected onMoreVideos () { | 140 | removeVideoFromArray (video: Video) { |
119 | this.videosModel = this.videos | 141 | this.videos = this.videos.filter(v => v.id !== video.id) |
120 | } | 142 | } |
121 | } | 143 | } |