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'
12 import { ScreenService } from '@app/shared/misc/screen.service'
15 selector: 'my-videos-search',
16 styleUrls: [ '../../shared/video/abstract-video-list.scss' ],
17 templateUrl: '../../shared/video/abstract-video-list.html'
19 export class VideoSearchComponent extends AbstractVideoList implements OnInit, OnDestroy {
21 currentRoute = '/videos/search'
24 protected otherRouteParams = {
27 private subActivatedRoute: Subscription
30 protected router: Router,
31 protected route: ActivatedRoute,
32 protected notificationsService: NotificationsService,
33 protected authService: AuthService,
34 protected location: Location,
36 protected screenService: ScreenService,
37 private videoService: VideoService,
38 private redirectService: RedirectService
42 this.titlePage = i18n('Search')
48 this.subActivatedRoute = this.route.queryParams.subscribe(
50 const querySearch = queryParams['search']
52 if (!querySearch) return this.redirectService.redirectToHomepage()
53 if (this.otherRouteParams.search === querySearch) return
55 this.otherRouteParams.search = querySearch
59 err => this.notificationsService.error('Error', err.text)
66 if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe()
69 getVideosObservable (page: number) {
70 const newPagination = immutableAssign(this.pagination, { currentPage: page })
71 return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort)
74 generateSyndicationList () {
75 throw new Error('Search does not support syndication.')