diff --git a/src/components/NavBar.vue b/src/components/NavBar.vue index fceb446a..6a046e1d 100644 --- a/src/components/NavBar.vue +++ b/src/components/NavBar.vue @@ -101,7 +101,7 @@ /> + + + + 10) searchHistory.shift(); + localStorage.setItem("search_history", JSON.stringify(searchHistory)); + }, }, }; diff --git a/src/components/SearchSuggestions.vue b/src/components/SearchSuggestions.vue index 74833955..2b5f9d80 100644 --- a/src/components/SearchSuggestions.vue +++ b/src/components/SearchSuggestions.vue @@ -47,11 +47,16 @@ export default { } }, async refreshSuggestions() { - this.searchSuggestions = ( - await this.fetchJson(this.apiUrl() + "/opensearch/suggestions", { - query: this.searchText, - }) - )?.[1]; + if (!this.searchText) { + if (this.getPreferenceBoolean("searchHistory", false)) + this.searchSuggestions = JSON.parse(localStorage.getItem("search_history")) ?? []; + } else { + this.searchSuggestions = ( + await this.fetchJson(this.apiUrl() + "/opensearch/suggestions", { + query: this.searchText, + }) + )?.[1]; + } this.searchSuggestions.unshift(this.searchText); this.setSelected(0); }, diff --git a/src/locales/en.json b/src/locales/en.json index 6474b63f..d97260ef 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -106,7 +106,8 @@ "follow_link": "Follow link", "copy_link": "Copy link", "time_code": "Time code (in seconds)", - "show_chapters": "Chapters" + "show_chapters": "Chapters", + "store_search_history": "Store Search history" }, "comment": { "pinned_by": "Pinned by",