aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/search/search.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-23 11:12:03 +0200
committerChocobozzz <me@florianbigard.com>2018-07-24 14:04:05 +0200
commit7afea880e561196671f186045c94f09511189405 (patch)
tree63d71c3c79a55e659a7359dbb17d47b84f1fb405 /client/src/app/search/search.component.ts
parent0b18f4aa80df8868bf34605423c7a298dffbb2aa (diff)
downloadPeerTube-7afea880e561196671f186045c94f09511189405.tar.gz
PeerTube-7afea880e561196671f186045c94f09511189405.tar.zst
PeerTube-7afea880e561196671f186045c94f09511189405.zip
Handle back/forward page in advanced search
Diffstat (limited to 'client/src/app/search/search.component.ts')
-rw-r--r--client/src/app/search/search.component.ts32
1 files changed, 17 insertions, 15 deletions
diff --git a/client/src/app/search/search.component.ts b/client/src/app/search/search.component.ts
index 09028fec5..8860b9268 100644
--- a/client/src/app/search/search.component.ts
+++ b/client/src/app/search/search.component.ts
@@ -27,6 +27,7 @@ export class SearchComponent implements OnInit, OnDestroy {
27 27
28 private subActivatedRoute: Subscription 28 private subActivatedRoute: Subscription
29 private currentSearch: string 29 private currentSearch: string
30 private isInitialLoad = true
30 31
31 constructor ( 32 constructor (
32 private i18n: I18n, 33 private i18n: I18n,
@@ -39,23 +40,28 @@ export class SearchComponent implements OnInit, OnDestroy {
39 ) { } 40 ) { }
40 41
41 ngOnInit () { 42 ngOnInit () {
42 this.advancedSearch = new AdvancedSearch(this.route.snapshot.queryParams)
43 if (this.advancedSearch.containsValues()) this.isSearchFilterCollapsed = false
44
45 this.subActivatedRoute = this.route.queryParams.subscribe( 43 this.subActivatedRoute = this.route.queryParams.subscribe(
46 queryParams => { 44 queryParams => {
47 const querySearch = queryParams['search'] 45 const querySearch = queryParams['search']
48 46
49 if (!querySearch) return this.redirectService.redirectToHomepage() 47 if (!querySearch) return this.redirectService.redirectToHomepage()
50 if (querySearch === this.currentSearch) return
51 48
52 // Search updated, reset filters 49 // Search updated, reset filters
53 if (this.currentSearch) this.advancedSearch.reset() 50 if (this.currentSearch !== querySearch) {
51 this.resetPagination()
52 this.advancedSearch.reset()
53
54 this.currentSearch = querySearch
55 this.updateTitle()
56 }
57
58 this.advancedSearch = new AdvancedSearch(queryParams)
54 59
55 this.currentSearch = querySearch 60 // Don't hide filters if we have some of them AND the user just came on the webpage
56 this.updateTitle() 61 this.isSearchFilterCollapsed = this.isInitialLoad === false || !this.advancedSearch.containsValues()
62 this.isInitialLoad = false
57 63
58 this.reload() 64 this.search()
59 }, 65 },
60 66
61 err => this.notificationsService.error('Error', err.text) 67 err => this.notificationsService.error('Error', err.text)
@@ -89,20 +95,16 @@ export class SearchComponent implements OnInit, OnDestroy {
89 } 95 }
90 96
91 onFiltered () { 97 onFiltered () {
92 this.updateUrlFromAdvancedSearch() 98 this.resetPagination()
93 // Hide the filters
94 this.isSearchFilterCollapsed = true
95 99
96 this.reload() 100 this.updateUrlFromAdvancedSearch()
97 } 101 }
98 102
99 private reload () { 103 private resetPagination () {
100 this.pagination.currentPage = 1 104 this.pagination.currentPage = 1
101 this.pagination.totalItems = null 105 this.pagination.totalItems = null
102 106
103 this.videos = [] 107 this.videos = []
104
105 this.search()
106 } 108 }
107 109
108 private updateTitle () { 110 private updateTitle () {