1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { RedirectService } from '@app/core'
4 import { immutableAssign } from '@app/shared/misc/utils'
5 import { NotificationsService } from 'angular2-notifications'
6 import { Subscription } from 'rxjs/Subscription'
7 import { AuthService } from '../../core/auth'
8 import { AbstractVideoList } from '../../shared/video/abstract-video-list'
9 import { VideoService } from '../../shared/video/video.service'
12 selector: 'my-videos-search',
13 styleUrls: [ '../../shared/video/abstract-video-list.scss' ],
14 templateUrl: '../../shared/video/abstract-video-list.html'
16 export class VideoSearchComponent extends AbstractVideoList implements OnInit, OnDestroy {
18 currentRoute = '/videos/search'
21 protected otherRouteParams = {
24 private subActivatedRoute: Subscription
26 constructor (protected router: Router,
27 protected route: ActivatedRoute,
28 protected notificationsService: NotificationsService,
29 protected authService: AuthService,
30 private videoService: VideoService,
31 private redirectService: RedirectService
39 this.subActivatedRoute = this.route.queryParams.subscribe(
41 const querySearch = queryParams['search']
42 if (!querySearch) return this.redirectService.redirectToHomepage()
43 if (this.otherRouteParams.search === querySearch) return
45 this.otherRouteParams.search = querySearch
49 err => this.notificationsService.error('Error', err.text)
56 if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe()
59 getVideosObservable (page: number) {
60 const newPagination = immutableAssign(this.pagination, { currentPage: page })
61 return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort)