diff options
Diffstat (limited to 'src/site')
| -rw-r--r-- | src/site/components/grid/Grid.vue | 12 | ||||
| -rw-r--r-- | src/site/pages/dashboard/index.vue | 16 | ||||
| -rw-r--r-- | src/site/store/images.js | 21 |
3 files changed, 39 insertions, 10 deletions
diff --git a/src/site/components/grid/Grid.vue b/src/site/components/grid/Grid.vue index 3a15335..ea568f0 100644 --- a/src/site/components/grid/Grid.vue +++ b/src/site/components/grid/Grid.vue @@ -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); } } }; diff --git a/src/site/pages/dashboard/index.vue b/src/site/pages/dashboard/index.vue index f94ca0d..41605f9 100644 --- a/src/site/pages/dashboard/index.vue +++ b/src/site/pages/dashboard/index.vue @@ -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 + }); + } } } }; diff --git a/src/site/store/images.js b/src/site/store/images.js index 7cf25ce..69b4f5e 100644 --- a/src/site/store/images.js +++ b/src/site/store/images.js @@ -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()); } |