]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/video-list/video-search.component.ts
Add ability to click on the account in watch page
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / video-list / video-search.component.ts
index 67726afdcaaf61769ffec590c072b88700999518..46a9dd48efe90e83d1cb11fcf9c63281556d407a 100644 (file)
@@ -1,5 +1,7 @@
 import { Component, OnDestroy, OnInit } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
+import { RedirectService } from '@app/core'
+import { immutableAssign } from '@app/shared/misc/utils'
 import { NotificationsService } from 'angular2-notifications'
 import { Subscription } from 'rxjs/Subscription'
 import { AuthService } from '../../core/auth'
@@ -16,7 +18,7 @@ export class VideoSearchComponent extends AbstractVideoList implements OnInit, O
   currentRoute = '/videos/search'
   loadOnInit = false
 
-  protected otherParams = {
+  protected otherRouteParams = {
     search: ''
   }
   private subActivatedRoute: Subscription
@@ -25,7 +27,9 @@ export class VideoSearchComponent extends AbstractVideoList implements OnInit, O
                protected route: ActivatedRoute,
                protected notificationsService: NotificationsService,
                protected authService: AuthService,
-               private videoService: VideoService) {
+               private videoService: VideoService,
+               private redirectService: RedirectService
+  ) {
     super()
   }
 
@@ -35,9 +39,11 @@ export class VideoSearchComponent extends AbstractVideoList implements OnInit, O
     this.subActivatedRoute = this.route.queryParams.subscribe(
       queryParams => {
         const querySearch = queryParams['search']
-        if (!querySearch || this.otherParams.search === querySearch) return
 
-        this.otherParams.search = querySearch
+        if (!querySearch) return this.redirectService.redirectToHomepage()
+        if (this.otherRouteParams.search === querySearch) return
+
+        this.otherRouteParams.search = querySearch
         this.reloadVideos()
       },
 
@@ -46,12 +52,17 @@ export class VideoSearchComponent extends AbstractVideoList implements OnInit, O
   }
 
   ngOnDestroy () {
-    if (this.subActivatedRoute) {
-      this.subActivatedRoute.unsubscribe()
-    }
+    super.ngOnDestroy()
+
+    if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe()
+  }
+
+  getVideosObservable (page: number) {
+    const newPagination = immutableAssign(this.pagination, { currentPage: page })
+    return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort)
   }
 
-  getVideosObservable () {
-    return this.videoService.searchVideos(this.otherParams.search, this.pagination, this.sort)
+  generateSyndicationList () {
+    throw new Error('Search does not support syndication.')
   }
 }