]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/videos/video-list/video-search.component.ts
Try to fix docker automatic build (again...)
[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 { RedirectService } from '@app/core'
4import { immutableAssign } from '@app/shared/misc/utils'
5import { NotificationsService } from 'angular2-notifications'
6import { Subscription } from 'rxjs/Subscription'
7import { AuthService } from '../../core/auth'
8import { AbstractVideoList } from '../../shared/video/abstract-video-list'
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
21 protected otherRouteParams = {
22 search: ''
23 }
24 private subActivatedRoute: Subscription
25
26 constructor (protected router: Router,
27 protected route: ActivatedRoute,
28 protected notificationsService: NotificationsService,
29 protected authService: AuthService,
30 private videoService: VideoService,
31 private redirectService: RedirectService
32 ) {
33 super()
34 }
35
36 ngOnInit () {
37 super.ngOnInit()
38
39 this.subActivatedRoute = this.route.queryParams.subscribe(
40 queryParams => {
41 const querySearch = queryParams['search']
42
43 if (!querySearch) return this.redirectService.redirectToHomepage()
44 if (this.otherRouteParams.search === querySearch) return
45
46 this.otherRouteParams.search = querySearch
47 this.reloadVideos()
48 },
49
50 err => this.notificationsService.error('Error', err.text)
51 )
52 }
53
54 ngOnDestroy () {
55 super.ngOnDestroy()
56
57 if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe()
58 }
59
60 getVideosObservable (page: number) {
61 const newPagination = immutableAssign(this.pagination, { currentPage: page })
62 return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort)
63 }
64}