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

@@ -77,6 +77,7 @@ export default {
mounted() {
if (this.handleRedirect()) return;
this.updateResults();
this.saveQueryToHistory();
},
activated() {
this.handleRedirect();
@@ -138,6 +139,15 @@ export default {
return true;
}
},
saveQueryToHistory() {
if (!this.getPreferenceBoolean("searchHistory", false)) return;
const query = this.$route.query.search_query;
if (!query) return;
const searchHistory = JSON.parse(localStorage.getItem("search_history")) ?? [];
if (!searchHistory.includes(query)) searchHistory.push(query);
if (searchHistory.length > 3) searchHistory.shift();
localStorage.setItem("search_history", JSON.stringify(searchHistory));
},
},
};
</script>