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 { Subscription } from 'rxjs/Subscription'
import { AuthService } from '../../core/auth'
currentRoute = '/videos/search'
loadOnInit = false
- private search = ''
+ protected otherRouteParams = {
+ search: ''
+ }
private subActivatedRoute: Subscription
constructor (protected router: Router,
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()
},
}
}
- 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)
}
}