]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/video-list/video-search.component.ts
Replace current state when changing page
[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'
f3aaa9a9 7import { Subscription } from 'rxjs/Subscription'
b2731bff 8import { AuthService } from '../../core/auth'
7bfd1b1e 9import { AbstractVideoList } from '../../shared/video/abstract-video-list'
f3aaa9a9
C
10import { VideoService } from '../../shared/video/video.service'
11
12@Component({
13 selector: 'my-videos-search',
14 styleUrls: [ '../../shared/video/abstract-video-list.scss' ],
15 templateUrl: '../../shared/video/abstract-video-list.html'
16})
17export class VideoSearchComponent extends AbstractVideoList implements OnInit, OnDestroy {
18 titlePage = 'Search'
19 currentRoute = '/videos/search'
20 loadOnInit = false
21
0cd4344f 22 protected otherRouteParams = {
c88593f7
C
23 search: ''
24 }
f3aaa9a9
C
25 private subActivatedRoute: Subscription
26
27 constructor (protected router: Router,
28 protected route: ActivatedRoute,
29 protected notificationsService: NotificationsService,
b2731bff 30 protected authService: AuthService,
2a2c19df 31 protected location: Location,
fc62e39c
C
32 private videoService: VideoService,
33 private redirectService: RedirectService
34 ) {
f3aaa9a9
C
35 super()
36 }
37
38 ngOnInit () {
39 super.ngOnInit()
40
41 this.subActivatedRoute = this.route.queryParams.subscribe(
42 queryParams => {
c88593f7 43 const querySearch = queryParams['search']
5b5e333f 44
fc62e39c
C
45 if (!querySearch) return this.redirectService.redirectToHomepage()
46 if (this.otherRouteParams.search === querySearch) return
c88593f7 47
0cd4344f 48 this.otherRouteParams.search = querySearch
f3aaa9a9
C
49 this.reloadVideos()
50 },
51
52 err => this.notificationsService.error('Error', err.text)
53 )
54 }
55
56 ngOnDestroy () {
9af61e84
C
57 super.ngOnDestroy()
58
59 if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe()
f3aaa9a9
C
60 }
61
0cd4344f
C
62 getVideosObservable (page: number) {
63 const newPagination = immutableAssign(this.pagination, { currentPage: page })
64 return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort)
f3aaa9a9 65 }
244e76a5
RK
66
67 generateSyndicationList () {
66dc5907 68 throw new Error('Search does not support syndication.')
244e76a5 69 }
f3aaa9a9 70}