]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/video-list/video-search.component.ts
Fix markdown links truncating
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / video-list / video-search.component.ts
index 241b97bc7e1aa75c288dfe904114a8d0f0006c65..b6434f3476cbdead09e3e09c94ba8a24273aa8f0 100644 (file)
@@ -1,11 +1,14 @@
 import { Component, OnDestroy, OnInit } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
+import { Location } from '@angular/common'
+import { RedirectService } from '@app/core'
 import { immutableAssign } from '@app/shared/misc/utils'
 import { NotificationsService } from 'angular2-notifications'
-import { Subscription } from 'rxjs/Subscription'
+import { Subscription } from 'rxjs'
 import { AuthService } from '../../core/auth'
 import { AbstractVideoList } from '../../shared/video/abstract-video-list'
 import { VideoService } from '../../shared/video/video.service'
+import { I18n } from '@ngx-translate/i18n-polyfill'
 
 @Component({
   selector: 'my-videos-search',
@@ -13,7 +16,7 @@ import { VideoService } from '../../shared/video/video.service'
   templateUrl: '../../shared/video/abstract-video-list.html'
 })
 export class VideoSearchComponent extends AbstractVideoList implements OnInit, OnDestroy {
-  titlePage = 'Search'
+  titlePage: string
   currentRoute = '/videos/search'
   loadOnInit = false
 
@@ -22,12 +25,19 @@ export class VideoSearchComponent extends AbstractVideoList implements OnInit, O
   }
   private subActivatedRoute: Subscription
 
-  constructor (protected router: Router,
-               protected route: ActivatedRoute,
-               protected notificationsService: NotificationsService,
-               protected authService: AuthService,
-               private videoService: VideoService) {
+  constructor (
+    protected router: Router,
+    protected route: ActivatedRoute,
+    protected notificationsService: NotificationsService,
+    protected authService: AuthService,
+    protected location: Location,
+    protected i18n: I18n,
+    private videoService: VideoService,
+    private redirectService: RedirectService
+  ) {
     super()
+
+    this.titlePage = i18n('Search')
   }
 
   ngOnInit () {
@@ -36,7 +46,9 @@ export class VideoSearchComponent extends AbstractVideoList implements OnInit, O
     this.subActivatedRoute = this.route.queryParams.subscribe(
       queryParams => {
         const querySearch = queryParams['search']
-        if (!querySearch || this.otherRouteParams.search === querySearch) return
+
+        if (!querySearch) return this.redirectService.redirectToHomepage()
+        if (this.otherRouteParams.search === querySearch) return
 
         this.otherRouteParams.search = querySearch
         this.reloadVideos()
@@ -47,13 +59,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)
   }
+
+  generateSyndicationList () {
+    throw new Error('Search does not support syndication.')
+  }
 }