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