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