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