From d8b34ee55b654912f86bb8b472d391ced8c28f64 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 13 Jan 2021 09:16:15 +0100 Subject: Allow user to search through their watch history (#3576) * allow user to search through their watch history * add tests for search in watch history * Update client/src/app/shared/shared-main/users/user-history.service.ts --- .../my-history/my-history.component.html | 19 +++++++++--- .../my-history/my-history.component.scss | 10 +++++-- .../+my-library/my-history/my-history.component.ts | 34 ++++++++++++++++++++-- .../my-subscriptions.component.html | 2 +- .../shared-main/users/user-history.service.ts | 3 +- 5 files changed, 58 insertions(+), 10 deletions(-) (limited to 'client/src') diff --git a/client/src/app/+my-library/my-history/my-history.component.html b/client/src/app/+my-library/my-history/my-history.component.html index 58b874ebf..c180161e7 100644 --- a/client/src/app/+my-library/my-history/my-history.component.html +++ b/client/src/app/+my-library/my-history/my-history.component.html @@ -1,12 +1,23 @@

- My history + My watch history {{ pagination.totalItems }}

-
+
+
+ + + Clear filters +
+
+ +
- +
-
You don't have any video history yet.
+
You don't have any video in your watch history yet.
diff --git a/client/src/app/+my-library/my-history/my-history.component.scss b/client/src/app/+my-library/my-history/my-history.component.scss index 9eeeaf310..928a8a3da 100644 --- a/client/src/app/+my-library/my-history/my-history.component.scss +++ b/client/src/app/+my-library/my-history/my-history.component.scss @@ -10,17 +10,23 @@ } .top-buttons { - margin-bottom: 20px; + margin-bottom: 30px; display: flex; align-items: center; flex-wrap: wrap; + #history-search { + @include peertube-input-text(250px); + } + .history-switch { display: flex; - flex-grow: 1; label { margin: 0 0 0 5px; + color: var(--greyForegroundColor); + font-size: 15px; + font-weight: $font-semibold; } } diff --git a/client/src/app/+my-library/my-history/my-history.component.ts b/client/src/app/+my-library/my-history/my-history.component.ts index 4ba95124d..0c8e4b83f 100644 --- a/client/src/app/+my-library/my-history/my-history.component.ts +++ b/client/src/app/+my-library/my-history/my-history.component.ts @@ -13,6 +13,8 @@ import { import { immutableAssign } from '@app/helpers' import { UserHistoryService } from '@app/shared/shared-main' import { AbstractVideoList } from '@app/shared/shared-video-miniature' +import { Subject } from 'rxjs' +import { debounceTime, tap, distinctUntilChanged } from 'rxjs/operators' @Component({ templateUrl: './my-history.component.html', @@ -26,6 +28,9 @@ export class MyHistoryComponent extends AbstractVideoList implements OnInit, OnD totalItems: null } videosHistoryEnabled: boolean + search: string + + protected searchStream: Subject constructor ( protected router: Router, @@ -41,7 +46,7 @@ export class MyHistoryComponent extends AbstractVideoList implements OnInit, OnD ) { super() - this.titlePage = $localize`My videos history` + this.titlePage = $localize`My watch history` } ngOnInit () { @@ -52,6 +57,28 @@ export class MyHistoryComponent extends AbstractVideoList implements OnInit, OnD this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled }) + this.searchStream = new Subject() + + this.searchStream + .pipe( + debounceTime(400), + distinctUntilChanged() + ) + .subscribe(search => { + this.search = search + this.reloadVideos() + }) + } + + onSearch (event: Event) { + const target = event.target as HTMLInputElement + this.searchStream.next(target.value) + } + + resetSearch () { + const searchInput = document.getElementById('history-search') as HTMLInputElement + searchInput.value = '' + this.searchStream.next('') } ngOnDestroy () { @@ -61,7 +88,10 @@ export class MyHistoryComponent extends AbstractVideoList implements OnInit, OnD getVideosObservable (page: number) { const newPagination = immutableAssign(this.pagination, { currentPage: page }) - return this.userHistoryService.getUserVideosHistory(newPagination) + return this.userHistoryService.getUserVideosHistory(newPagination, this.search) + .pipe( + tap(res => this.pagination.totalItems = res.total) + ) } generateSyndicationList () { diff --git a/client/src/app/+my-library/my-subscriptions/my-subscriptions.component.html b/client/src/app/+my-library/my-subscriptions/my-subscriptions.component.html index 6ab3826ba..510b400c0 100644 --- a/client/src/app/+my-library/my-subscriptions/my-subscriptions.component.html +++ b/client/src/app/+my-library/my-subscriptions/my-subscriptions.component.html @@ -15,7 +15,7 @@
-
You don't have any subscriptions yet.
+
You don't have any subscription yet.
diff --git a/client/src/app/shared/shared-main/users/user-history.service.ts b/client/src/app/shared/shared-main/users/user-history.service.ts index 43970dc5b..bb87dcba8 100644 --- a/client/src/app/shared/shared-main/users/user-history.service.ts +++ b/client/src/app/shared/shared-main/users/user-history.service.ts @@ -18,11 +18,12 @@ export class UserHistoryService { private videoService: VideoService ) {} - getUserVideosHistory (historyPagination: ComponentPaginationLight) { + getUserVideosHistory (historyPagination: ComponentPaginationLight, search?: string) { const pagination = this.restService.componentPaginationToRestPagination(historyPagination) let params = new HttpParams() params = this.restService.addRestGetParams(params, pagination) + params = params.append('search', search) return this.authHttp .get>(UserHistoryService.BASE_USER_VIDEOS_HISTORY_URL, { params }) -- cgit v1.2.3