1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { Location } from '@angular/common'
4 import { RedirectService } from '@app/core'
5 import { immutableAssign } from '@app/shared/misc/utils'
6 import { NotificationsService } from 'angular2-notifications'
7 import { Subscription } from 'rxjs'
8 import { AuthService } from '../../core/auth'
9 import { AbstractVideoList } from '../../shared/video/abstract-video-list'
10 import { VideoService } from '../../shared/video/video.service'
13 selector: 'my-videos-search',
14 styleUrls: [ '../../shared/video/abstract-video-list.scss' ],
15 templateUrl: '../../shared/video/abstract-video-list.html'
17 export class VideoSearchComponent extends AbstractVideoList implements OnInit, OnDestroy {
19 currentRoute = '/videos/search'
22 protected otherRouteParams = {
25 private subActivatedRoute: Subscription
27 constructor (protected router: Router,
28 protected route: ActivatedRoute,
29 protected notificationsService: NotificationsService,
30 protected authService: AuthService,
31 protected location: Location,
32 private videoService: VideoService,
33 private redirectService: RedirectService
41 this.subActivatedRoute = this.route.queryParams.subscribe(
43 const querySearch = queryParams['search']
45 if (!querySearch) return this.redirectService.redirectToHomepage()
46 if (this.otherRouteParams.search === querySearch) return
48 this.otherRouteParams.search = querySearch
52 err => this.notificationsService.error('Error', err.text)
59 if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe()
62 getVideosObservable (page: number) {
63 const newPagination = immutableAssign(this.pagination, { currentPage: page })
64 return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort)
67 generateSyndicationList () {
68 throw new Error('Search does not support syndication.')