]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
f3aaa9a9
C
1import { Component, OnDestroy, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router'
2a2c19df 3import { Location } from '@angular/common'
fc62e39c 4import { RedirectService } from '@app/core'
0cd4344f 5import { immutableAssign } from '@app/shared/misc/utils'
f3aaa9a9 6import { NotificationsService } from 'angular2-notifications'
db400f44 7import { Subscription } from 'rxjs'
b2731bff 8import { AuthService } from '../../core/auth'
7bfd1b1e 9import { AbstractVideoList } from '../../shared/video/abstract-video-list'
f3aaa9a9 10import { VideoService } from '../../shared/video/video.service'
989e526a 11import { I18n } from '@ngx-translate/i18n-polyfill'
f3aaa9a9
C
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 {
989e526a 19 titlePage: string
f3aaa9a9
C
20 currentRoute = '/videos/search'
21 loadOnInit = false
22
0cd4344f 23 protected otherRouteParams = {
c88593f7
C
24 search: ''
25 }
f3aaa9a9
C
26 private subActivatedRoute: Subscription
27
989e526a
C
28 constructor (
29 protected router: Router,
30 protected route: ActivatedRoute,
31 protected notificationsService: NotificationsService,
32 protected authService: AuthService,
33 protected location: Location,
b1d40cff 34 protected i18n: I18n,
989e526a 35 private videoService: VideoService,
b1d40cff 36 private redirectService: RedirectService
fc62e39c 37 ) {
f3aaa9a9 38 super()
989e526a
C
39
40 this.titlePage = i18n('Search')
f3aaa9a9
C
41 }
42
43 ngOnInit () {
44 super.ngOnInit()
45
46 this.subActivatedRoute = this.route.queryParams.subscribe(
47 queryParams => {
c88593f7 48 const querySearch = queryParams['search']
5b5e333f 49
fc62e39c
C
50 if (!querySearch) return this.redirectService.redirectToHomepage()
51 if (this.otherRouteParams.search === querySearch) return
c88593f7 52
0cd4344f 53 this.otherRouteParams.search = querySearch
f3aaa9a9
C
54 this.reloadVideos()
55 },
56
57 err => this.notificationsService.error('Error', err.text)
58 )
59 }
60
61 ngOnDestroy () {
9af61e84
C
62 super.ngOnDestroy()
63
64 if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe()
f3aaa9a9
C
65 }
66
0cd4344f
C
67 getVideosObservable (page: number) {
68 const newPagination = immutableAssign(this.pagination, { currentPage: page })
69 return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort)
f3aaa9a9 70 }
244e76a5
RK
71
72 generateSyndicationList () {
66dc5907 73 throw new Error('Search does not support syndication.')
244e76a5 74 }
f3aaa9a9 75}