]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/videos/video-list/video-search.component.ts
Fix markdown links truncating
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / video-list / video-search.component.ts
... / ...
CommitLineData
1import { Component, OnDestroy, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router'
3import { Location } from '@angular/common'
4import { RedirectService } from '@app/core'
5import { immutableAssign } from '@app/shared/misc/utils'
6import { NotificationsService } from 'angular2-notifications'
7import { Subscription } from 'rxjs'
8import { AuthService } from '../../core/auth'
9import { AbstractVideoList } from '../../shared/video/abstract-video-list'
10import { VideoService } from '../../shared/video/video.service'
11import { 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})
18export 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 protected i18n: I18n,
35 private videoService: VideoService,
36 private redirectService: RedirectService
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}