From 39e9941ded8de4e41048781daa80de0838c01c19 Mon Sep 17 00:00:00 2001 From: Zephyrrus Date: Thu, 23 Jul 2020 04:08:31 +0300 Subject: [PATCH] feat: Add hiding to recommendations as a prop fix: change some of the regexes to remove , and ; as separator support because the query parser doesn't understad them and I don't feel like dealing with all the edge cases introduces by it --- src/site/components/search/Search.vue | 35 ++++++++++++++++++------- src/site/pages/dashboard/albums/_id.vue | 21 +++++++-------- src/site/pages/dashboard/index.vue | 10 ++++++- src/site/store/images.js | 6 +++++ 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/src/site/components/search/Search.vue b/src/site/components/search/Search.vue index 57226a9..72a5707 100644 --- a/src/site/components/search/Search.vue +++ b/src/site/components/search/Search.vue @@ -12,7 +12,8 @@ placeholder="Search" type="search" open-on-focus - @typing="handleTyping"> + @typing="handleTyping" + @keydown.native.enter="onSubmit"> @@ -75,11 +70,13 @@ import { mapState, mapGetters, mapActions } from 'vuex'; import Sidebar from '~/components/sidebar/Sidebar.vue'; import Grid from '~/components/grid/Grid.vue'; +import Search from '~/components/search/Search.vue'; export default { components: { Sidebar, Grid, + Search, }, middleware: ['auth', ({ route, store }) => { store.commit('images/resetState'); diff --git a/src/site/pages/dashboard/index.vue b/src/site/pages/dashboard/index.vue index cfd68ba..096f4e3 100644 --- a/src/site/pages/dashboard/index.vue +++ b/src/site/pages/dashboard/index.vue @@ -103,8 +103,16 @@ export default { await this.fetch(this.current); this.isLoading = false; }, + sanitizeQuery(qry) { + // remove spaces between a search type selector `album:` + // and the value (ex `tag: 123` -> `tag:123`) + return (qry || '').replace(/(\w+):\s+/gi, '$1:'); + }, onSearch(query) { - this.searc = query; + this.search = query; + this.$handler.executeAction('images/search', { + q: this.sanitizeQuery(query), + }); }, }, }; diff --git a/src/site/store/images.js b/src/site/store/images.js index 4737c26..0488573 100644 --- a/src/site/store/images.js +++ b/src/site/store/images.js @@ -106,6 +106,12 @@ export const actions = { commit('removeTagFromFile', response.data); + return response; + }, + async search({ commit }, { q, albumId }) { + const optionalAlbum = albumId ? `&albumId=${albumId}` : ''; + const response = await this.$axios.$get(`search/?q=${encodeURI(q)}${optionalAlbum}`); + return response; }, };