Change:persist last search term #142

This commit is contained in:
advplyr 2022-04-26 17:05:49 -05:00
parent d64dd63ea4
commit be885009ad
3 changed files with 20 additions and 3 deletions

View file

@ -18,7 +18,7 @@
<widgets-download-progress-indicator /> <widgets-download-progress-indicator />
<!-- Must be connected to a server to cast, only supports media items on server --> <!-- Must be connected to a server to cast, only supports media items on server -->
<div v-show="isCastAvailable && user" class="mx-2 cursor-pointer mt-1"> <div v-show="isCastAvailable && user" class="mx-2 cursor-pointer mt-1.5">
<span class="material-icons" :class="isCasting ? 'text-success' : ''" style="font-size: 1.6rem" @click="castClick">cast</span> <span class="material-icons" :class="isCasting ? 'text-success' : ''" style="font-size: 1.6rem" @click="castClick">cast</span>
</div> </div>

View file

@ -76,7 +76,11 @@ export default {
}, },
methods: { methods: {
async runSearch(value) { async runSearch(value) {
if (this.isFetching && this.lastSearch === value) return
this.lastSearch = value this.lastSearch = value
this.$store.commit('globals/setLastSearch', value)
if (!this.lastSearch) { if (!this.lastSearch) {
this.bookResults = [] this.bookResults = []
this.podcastResults = [] this.podcastResults = []
@ -89,6 +93,10 @@ export default {
console.error('Search error', error) console.error('Search error', error)
return [] return []
}) })
if (value !== this.lastSearch) {
console.log(`runSearch: New search was made for ${this.lastSearch} - results are from ${value}`)
return
}
console.log('RESULTS', results) console.log('RESULTS', results)
this.isFetching = false this.isFetching = false
@ -113,8 +121,13 @@ export default {
} }
}, },
mounted() { mounted() {
if (this.$store.state.globals.lastSearch) {
this.search = this.$store.state.globals.lastSearch
this.runSearch(this.search)
} else {
this.$nextTick(this.setFocus()) this.$nextTick(this.setFocus())
} }
}
} }
</script> </script>

View file

@ -2,7 +2,8 @@ export const state = () => ({
itemDownloads: [], itemDownloads: [],
bookshelfListView: false, bookshelfListView: false,
series: null, series: null,
localMediaProgress: [] localMediaProgress: [],
lastSearch: null
}) })
export const getters = { export const getters = {
@ -82,5 +83,8 @@ export const mutations = {
}, },
removeLocalMediaProgress(state, id) { removeLocalMediaProgress(state, id) {
state.localMediaProgress = state.localMediaProgress.filter(lmp => lmp.id != id) state.localMediaProgress = state.localMediaProgress.filter(lmp => lmp.id != id)
},
setLastSearch(state, val) {
state.lastSearch = val
} }
} }