X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fvideos%2Fvideo-list%2Fvideo-search.component.ts;h=788797a4cf6cfcaf9f10407ed32c3159f8792a94;hb=9af61e84309c23ffbfd7562435a5fadd86cdf20c;hp=ba851d27e6553f5c74be195cfe0c24243f7a1a82;hpb=fada8d75550dc7365f7e18ee1569b9406251d660;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/videos/video-list/video-search.component.ts b/client/src/app/videos/video-list/video-search.component.ts index ba851d27e..788797a4c 100644 --- a/client/src/app/videos/video-list/video-search.component.ts +++ b/client/src/app/videos/video-list/video-search.component.ts @@ -1,9 +1,10 @@ import { Component, OnDestroy, OnInit } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' +import { immutableAssign } from '@app/shared/misc/utils' import { NotificationsService } from 'angular2-notifications' -import { AbstractVideoList } from 'app/shared/video/abstract-video-list' import { Subscription } from 'rxjs/Subscription' -import { SortField } from '../../shared/video/sort-field.type' +import { AuthService } from '../../core/auth' +import { AbstractVideoList } from '../../shared/video/abstract-video-list' import { VideoService } from '../../shared/video/video.service' @Component({ @@ -16,12 +17,15 @@ export class VideoSearchComponent extends AbstractVideoList implements OnInit, O currentRoute = '/videos/search' loadOnInit = false - private search = '' + protected otherRouteParams = { + search: '' + } private subActivatedRoute: Subscription constructor (protected router: Router, protected route: ActivatedRoute, protected notificationsService: NotificationsService, + protected authService: AuthService, private videoService: VideoService) { super() } @@ -31,7 +35,10 @@ export class VideoSearchComponent extends AbstractVideoList implements OnInit, O this.subActivatedRoute = this.route.queryParams.subscribe( queryParams => { - this.search = queryParams['search'] + const querySearch = queryParams['search'] + if (!querySearch || this.otherRouteParams.search === querySearch) return + + this.otherRouteParams.search = querySearch this.reloadVideos() }, @@ -40,12 +47,13 @@ export class VideoSearchComponent extends AbstractVideoList implements OnInit, O } ngOnDestroy () { - if (this.subActivatedRoute) { - this.subActivatedRoute.unsubscribe() - } + super.ngOnDestroy() + + if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe() } - getVideosObservable () { - return this.videoService.searchVideos(this.search, this.pagination, this.sort) + getVideosObservable (page: number) { + const newPagination = immutableAssign(this.pagination, { currentPage: page }) + return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort) } }