]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/search/search.component.ts
Merge branch 'feature/webtorrent-disabling' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / search / search.component.ts
index 475fdd277628469bf1a821097612367edd3da591..ecffcafc1ff09621804704cf4ecddaef5a18148d 100644 (file)
@@ -1,6 +1,6 @@
 import { Component, OnDestroy, OnInit } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
-import { AuthService, RedirectService } from '@app/core'
+import { AuthService } from '@app/core'
 import { NotificationsService } from 'angular2-notifications'
 import { forkJoin, Subscription } from 'rxjs'
 import { SearchService } from '@app/search/search.service'
@@ -30,7 +30,7 @@ export class SearchComponent implements OnInit, OnDestroy {
   currentSearch: string
 
   private subActivatedRoute: Subscription
-  private isInitialLoad = true
+  private isInitialLoad = false // set to false to show the search filters on first arrival
   private firstSearch = true
 
   private channelsPerPage = 2
@@ -40,7 +40,6 @@ export class SearchComponent implements OnInit, OnDestroy {
     private route: ActivatedRoute,
     private router: Router,
     private metaService: MetaService,
-    private redirectService: RedirectService,
     private notificationsService: NotificationsService,
     private searchService: SearchService,
     private authService: AuthService
@@ -51,15 +50,12 @@ export class SearchComponent implements OnInit, OnDestroy {
       queryParams => {
         const querySearch = queryParams['search']
 
-        // New empty search
-        if (this.currentSearch && !querySearch) return this.redirectService.redirectToHomepage()
-
         // Search updated, reset filters
         if (this.currentSearch !== querySearch) {
           this.resetPagination()
           this.advancedSearch.reset()
 
-          this.currentSearch = querySearch
+          this.currentSearch = querySearch || undefined
           this.updateTitle()
         }
 
@@ -137,6 +133,10 @@ export class SearchComponent implements OnInit, OnDestroy {
     this.updateUrlFromAdvancedSearch()
   }
 
+  numberOfFilters () {
+    return this.advancedSearch.size()
+  }
+
   private resetPagination () {
     this.pagination.currentPage = 1
     this.pagination.totalItems = null
@@ -150,9 +150,11 @@ export class SearchComponent implements OnInit, OnDestroy {
   }
 
   private updateUrlFromAdvancedSearch () {
+    const search = this.currentSearch || undefined
+
     this.router.navigate([], {
       relativeTo: this.route,
-      queryParams: Object.assign({}, this.advancedSearch.toUrlObject(), { search: this.currentSearch })
+      queryParams: Object.assign({}, this.advancedSearch.toUrlObject(), { search })
     })
   }
 }