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; }, };