]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/video-list/video-search.component.ts
Prepare i18n files
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / video-list / video-search.component.ts
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
13 @Component({
14 selector: 'my-videos-search',
15 styleUrls: [ '../../shared/video/abstract-video-list.scss' ],
16 templateUrl: '../../shared/video/abstract-video-list.html'
17 })
18 export class VideoSearchComponent extends AbstractVideoList implements OnInit, OnDestroy {
19 titlePage: string
20 currentRoute = '/videos/search'
21 loadOnInit = false
22
23 protected otherRouteParams = {
24 search: ''
25 }
26 private subActivatedRoute: Subscription
27
28 constructor (
29 protected router: Router,
30 protected route: ActivatedRoute,
31 protected notificationsService: NotificationsService,
32 protected authService: AuthService,
33 protected location: Location,
34 private videoService: VideoService,
35 private redirectService: RedirectService,
36 private i18n: I18n
37 ) {
38 super()
39
40 this.titlePage = i18n('Search')
41 }
42
43 ngOnInit () {
44 super.ngOnInit()
45
46 this.subActivatedRoute = this.route.queryParams.subscribe(
47 queryParams => {
48 const querySearch = queryParams['search']
49
50 if (!querySearch) return this.redirectService.redirectToHomepage()
51 if (this.otherRouteParams.search === querySearch) return
52
53 this.otherRouteParams.search = querySearch
54 this.reloadVideos()
55 },
56
57 err => this.notificationsService.error('Error', err.text)
58 )
59 }
60
61 ngOnDestroy () {
62 super.ngOnDestroy()
63
64 if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe()
65 }
66
67 getVideosObservable (page: number) {
68 const newPagination = immutableAssign(this.pagination, { currentPage: page })
69 return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort)
70 }
71
72 generateSyndicationList () {
73 throw new Error('Search does not support syndication.')
74 }
75 }