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 ++++++++++++++++++++-- 3 files changed, 55 insertions(+), 8 deletions(-) (limited to 'client/src/app/+my-library/my-history') 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 () { -- cgit v1.2.3