bug: fix showlist resetting itself every time the page is changed

bug: fix store not commiting search results
This commit is contained in:
Zephyrrus 2020-12-24 13:57:09 +02:00
parent d2efb2707c
commit 587f7d69e8
3 changed files with 39 additions and 10 deletions

View File

@ -21,9 +21,8 @@
</div>
</nav>
<template v-if="!showList">
<template v-if="!images.showList">
<Waterfall
v-if="showWaterfall"
:gutterWidth="10"
:gutterHeight="4"
:options="{fitWidth: true}"
@ -196,7 +195,6 @@ export default {
},
data() {
return {
showWaterfall: true,
searchTerm: null,
showList: false,
hoveredItems: [],
@ -226,10 +224,15 @@ export default {
return (this.files || []).filter((v) => !v.hideFromList);
}
},
watch: {
showList: 'displayTypeChange'
},
created() {
// TODO: Create a middleware for this
this.getAlbums();
this.getTags();
this.showList = this.images.showList;
},
methods: {
async search() {
@ -332,6 +335,9 @@ export default {
},
isHovered(id) {
return this.hoveredItems.includes(id);
},
displayTypeChange(showList) {
this.$store.commit('images/setShowList', showList);
}
}
};

View File

@ -108,11 +108,19 @@ export default {
// and the value (ex `tag: 123` -> `tag:123`)
return (qry || '').replace(/(\w+):\s+/gi, '$1:');
},
onSearch(query) {
async onSearch(query) {
this.search = query;
this.$handler.executeAction('images/search', {
q: this.sanitizeQuery(query)
});
const sanitizedQ = this.sanitizeQuery(query);
if (!sanitizedQ.length) {
this.current = 1;
await this.fetch(this.current);
} else {
this.$handler.executeAction('images/search', {
q: this.sanitizeQuery(query),
page: this.current
});
}
}
}
};

View File

@ -9,6 +9,7 @@ export const getDefaultState = () => ({
totalFiles: 0
},
search: '',
showList: false,
albumName: null,
albumDownloadEnabled: false,
fileExtraInfoMap: {}, // information about the selected file
@ -108,11 +109,22 @@ export const actions = {
return response;
},
async search({ commit }, { q, albumId }) {
async search({ commit, dispatch }, { q, albumId, page }) {
const optionalAlbum = albumId ? `&albumId=${albumId}` : '';
const response = await this.$axios.$get(`search/?q=${encodeURI(q)}${optionalAlbum}`);
return response;
page = page || 1;
try {
const response = await this.$axios.$get(`search/?q=${encodeURI(q)}${optionalAlbum}`);
commit('setFilesAndMeta', { ...response, page });
return response;
} catch (e) {
dispatch('alert/set', { text: e.message, error: true }, { root: true });
}
return null;
}
};
@ -172,6 +184,9 @@ export const mutations = {
state.fileTagsMap[fileId].splice(foundIndex, 1);
}
},
setShowList(state, showList) {
state.showList = showList;
},
resetState(state) {
Object.assign(state, getDefaultState());
}