Add search retry functionality

This commit implements query invalidation logic that runs when the
requested query is same as the last one. This allows for seamless
retries of previous searches without reloading or moving around routes,
improving user experience and reducing bandwidth usage.

Note that this commit does not change the behavior of the search bar
located in the app header.
This commit is contained in:
itepechi 2024-05-09 14:15:45 +09:00
parent 76b44d3a39
commit 105da507d7
Signed by: itepechi
GPG Key ID: D948CE1B5ACD0B25
1 changed files with 8 additions and 2 deletions

View File

@ -95,8 +95,14 @@ const Search = {
},
methods: {
newQuery (query) {
this.$router.push({ name: 'search', query: { query } })
this.$refs.searchInput.focus()
if (this.lastQuery === query) {
// Handle search retries
this.lastQuery = "" // invalidate state
this.search(query)
} else {
this.$router.push({ name: 'search', query: { query } })
this.$refs.searchInput.focus()
}
},
async search (query, searchType = null) {
if (!query) {