]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/search/search.component.ts
Fix responsive on videos search
[github/Chocobozzz/PeerTube.git] / client / src / app / search / search.component.ts
index 09028fec5e0f75c8cdbc1835b0d367bdfe7c7081..8d615fd058dd990674217300592a632870ab6629 100644 (file)
@@ -27,6 +27,7 @@ export class SearchComponent implements OnInit, OnDestroy {
 
   private subActivatedRoute: Subscription
   private currentSearch: string
+  private isInitialLoad = true
 
   constructor (
     private i18n: I18n,
@@ -39,23 +40,29 @@ export class SearchComponent implements OnInit, OnDestroy {
   ) { }
 
   ngOnInit () {
-    this.advancedSearch = new AdvancedSearch(this.route.snapshot.queryParams)
-    if (this.advancedSearch.containsValues()) this.isSearchFilterCollapsed = false
-
     this.subActivatedRoute = this.route.queryParams.subscribe(
       queryParams => {
         const querySearch = queryParams['search']
 
-        if (!querySearch) return this.redirectService.redirectToHomepage()
-        if (querySearch === this.currentSearch) return
+        // New empty search
+        if (this.currentSearch && !querySearch) return this.redirectService.redirectToHomepage()
 
         // Search updated, reset filters
-        if (this.currentSearch) this.advancedSearch.reset()
+        if (this.currentSearch !== querySearch) {
+          this.resetPagination()
+          this.advancedSearch.reset()
+
+          this.currentSearch = querySearch
+          this.updateTitle()
+        }
+
+        this.advancedSearch = new AdvancedSearch(queryParams)
 
-        this.currentSearch = querySearch
-        this.updateTitle()
+        // Don't hide filters if we have some of them AND the user just came on the webpage
+        this.isSearchFilterCollapsed = this.isInitialLoad === false || !this.advancedSearch.containsValues()
+        this.isInitialLoad = false
 
-        this.reload()
+        this.search()
       },
 
       err => this.notificationsService.error('Error', err.text)
@@ -89,20 +96,16 @@ export class SearchComponent implements OnInit, OnDestroy {
   }
 
   onFiltered () {
-    this.updateUrlFromAdvancedSearch()
-    // Hide the filters
-    this.isSearchFilterCollapsed = true
+    this.resetPagination()
 
-    this.reload()
+    this.updateUrlFromAdvancedSearch()
   }
 
-  private reload () {
+  private resetPagination () {
     this.pagination.currentPage = 1
     this.pagination.totalItems = null
 
     this.videos = []
-
-    this.search()
   }
 
   private updateTitle () {