mirror of
https://github.com/TeamPiped/Piped.git
synced 2025-12-29 16:02:39 +00:00
add search history
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user