fix: search caching keeping old search after changing term

This commit is contained in:
Roberto Tonino 2020-11-28 17:34:22 +01:00
parent bd753865a0
commit 6789ea8be4
2 changed files with 9 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -143,16 +143,17 @@ export default defineComponent({
const searchedTerm = computed(() => ctx.root.$route.query.term) const searchedTerm = computed(() => ctx.root.$route.query.term)
const isSearching = ref(false) const isSearching = ref(false)
const isMainSearchCached = computed(() => Object.keys(searchResult.value).length !== 0) const isMainSearchCached = computed(() => Object.keys(searchResult.value).length !== 0)
const isNewQuery = computed(() => searchResult.value.QUERY !== searchedTerm.value)
console.log('onSetup', lastTab.value) console.log('onSetup', lastTab.value)
if (isMainSearchCached.value) { if (isMainSearchCached.value && !isNewQuery.value) {
console.log('main search cached!') console.log('main search cached!')
onMounted(() => { onMounted(() => {
handleMainSearch(searchResult.value) handleMainSearch(searchResult.value)
}) })
} }
if (searchedTerm.value && !isMainSearchCached.value) { if (searchedTerm.value && (!isMainSearchCached.value || isNewQuery.value)) {
console.log('need to perform main search') console.log('need to perform main search')
performMainSearch(searchedTerm.value) performMainSearch(searchedTerm.value)
isSearching.value = true isSearching.value = true
@ -225,7 +226,11 @@ export default defineComponent({
isQueryEmpty, isQueryEmpty,
searchResult, searchResult,
performMainSearch, performMainSearch,
performSearch performSearch,
// Remove
isNewQuery,
searchedTerm,
isMainSearchCached
} }
}, },
computed: { computed: {