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'
11 import { I18n } from '@ngx-translate/i18n-polyfill'
14 selector: 'my-videos-search',
15 styleUrls: [ '../../shared/video/abstract-video-list.scss' ],
16 templateUrl: '../../shared/video/abstract-video-list.html'
18 export class VideoSearchComponent extends AbstractVideoList implements OnInit, OnDestroy {
20 currentRoute = '/videos/search'
23 protected otherRouteParams = {
26 private subActivatedRoute: Subscription
29 protected router: Router,
30 protected route: ActivatedRoute,
31 protected notificationsService: NotificationsService,
32 protected authService: AuthService,
33 protected location: Location,
35 private videoService: VideoService,
36 private redirectService: RedirectService
40 this.titlePage = i18n('Search')
46 this.subActivatedRoute = this.route.queryParams.subscribe(
48 const querySearch = queryParams['search']
50 if (!querySearch) return this.redirectService.redirectToHomepage()
51 if (this.otherRouteParams.search === querySearch) return
53 this.otherRouteParams.search = querySearch
57 err => this.notificationsService.error('Error', err.text)
64 if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe()
67 getVideosObservable (page: number) {
68 const newPagination = immutableAssign(this.pagination, { currentPage: page })
69 return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort)
72 generateSyndicationList () {
73 throw new Error('Search does not support syndication.')