Ensure most recent search is on top.

This commit is contained in:
Kavin 2022-10-02 14:23:16 +01:00
parent 09582cb502
commit f920a1aae8
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

@ -144,7 +144,11 @@ export default {
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.includes(query)) {
const index = searchHistory.indexOf(query);
searchHistory.splice(index, 1);
}
searchHistory.unshift(query);
if (searchHistory.length > 10) searchHistory.shift();
localStorage.setItem("search_history", JSON.stringify(searchHistory));
},