add search history

This commit is contained in:
Bnyro
2022-09-11 20:01:58 +02:00
committed by Kavin
parent 7308e19f6c
commit cdfa850081
5 changed files with 39 additions and 7 deletions

View File

@@ -47,11 +47,15 @@ export default {
}
},
async refreshSuggestions() {
this.searchSuggestions = (
await this.fetchJson(this.apiUrl() + "/opensearch/suggestions", {
query: this.searchText,
})
)?.[1];
if (!this.searchText) {
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);
},