1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { immutableAssign } from '@app/shared/misc/utils'
4 import { NotificationsService } from 'angular2-notifications'
5 import { Subscription } from 'rxjs/Subscription'
6 import { AuthService } from '../../core/auth'
7 import { AbstractVideoList } from '../../shared/video/abstract-video-list'
8 import { VideoService } from '../../shared/video/video.service'
11 selector: 'my-videos-search',
12 styleUrls: [ '../../shared/video/abstract-video-list.scss' ],
13 templateUrl: '../../shared/video/abstract-video-list.html'
15 export class VideoSearchComponent extends AbstractVideoList implements OnInit, OnDestroy {
17 currentRoute = '/videos/search'
20 protected otherRouteParams = {
23 private subActivatedRoute: Subscription
25 constructor (protected router: Router,
26 protected route: ActivatedRoute,
27 protected notificationsService: NotificationsService,
28 protected authService: AuthService,
29 private videoService: VideoService) {
36 this.subActivatedRoute = this.route.queryParams.subscribe(
38 const querySearch = queryParams['search']
39 if (!querySearch || this.otherRouteParams.search === querySearch) return
41 this.otherRouteParams.search = querySearch
45 err => this.notificationsService.error('Error', err.text)
50 if (this.subActivatedRoute) {
51 this.subActivatedRoute.unsubscribe()
55 getVideosObservable (page: number) {
56 const newPagination = immutableAssign(this.pagination, { currentPage: page })
57 return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort)