]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/videos/video-list/video-search.component.ts
Add redis cache to feed route
[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'
10import { FeedFormat } from '../../../../../shared/models/feeds/feed-format.enum'
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
22 protected otherRouteParams = {
23 search: ''
24 }
25 private subActivatedRoute: Subscription
26
27 constructor (protected router: Router,
28 protected route: ActivatedRoute,
29 protected notificationsService: NotificationsService,
30 protected authService: AuthService,
31 private videoService: VideoService,
32 private redirectService: RedirectService
33 ) {
34 super()
35 }
36
37 ngOnInit () {
38 super.ngOnInit()
39
40 this.subActivatedRoute = this.route.queryParams.subscribe(
41 queryParams => {
42 const querySearch = queryParams['search']
43
44 if (!querySearch) return this.redirectService.redirectToHomepage()
45 if (this.otherRouteParams.search === querySearch) return
46
47 this.otherRouteParams.search = querySearch
48 this.reloadVideos()
49 },
50
51 err => this.notificationsService.error('Error', err.text)
52 )
53 }
54
55 ngOnDestroy () {
56 super.ngOnDestroy()
57
58 if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe()
59 }
60
61 getVideosObservable (page: number) {
62 const newPagination = immutableAssign(this.pagination, { currentPage: page })
63 return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort)
64 }
65
66 generateSyndicationList () {
67 throw new Error('Method not implemented.')
68 }
69}