Skip to content

Commit

Permalink
refactor(Search page): many small improvements on the search form
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed May 23, 2024
1 parent 2092f48 commit edcdf3a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/LocationSelectorDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export default {
}
},
search() {
this.$refs.locationInput.blur()
this.results = null
this.loading = true
api.openstreetmapSearch(this.locationSearchForm.q, this.searchProvider)
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default {
{ key: 'opf', value: OPF_NAME, icon: OPF_ICON },
{ key: 'opff', value: OPFF_NAME, icon: OPFF_ICON },
],
QUERY_PARAM: 'q',
FILTER_PARAM: 'filter',
PRODUCT_FILTER_LIST: [
{ key: 'hide_price_count_gte_1', value: 'FilterProductWithPriceCountHide' },
Expand Down
30 changes: 25 additions & 5 deletions src/views/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
<v-col>
<v-form @submit.prevent="search">
<v-text-field
ref="searchInput"
v-model="productSearchForm.q"
:label="$t('Search.ProductBarcode')"
type="number"
inputmode="numeric"
:prepend-inner-icon="formFilled ? 'mdi-barcode' : 'mdi-barcode-scan'"
append-inner-icon="mdi-magnify"
@click:prepend-inner="showBarcodeScannerDialog"
@click:append-inner="search"
:rules="[fieldRequired]"
hide-details="auto"
:loading="loading"
required>
<template v-slot:prepend-inner>
<v-icon :icon="formFilled ? 'mdi-barcode' : 'mdi-barcode-scan'" @click="showBarcodeScannerDialog"></v-icon>
</template>
<template v-slot:append-inner>
<v-icon icon="mdi-magnify" @click="search"></v-icon>
</template>
</v-text-field>
</v-form>
</v-col>
Expand All @@ -44,6 +48,7 @@

<script>
import { defineAsyncComponent } from 'vue'
import constants from '../constants'
import api from '../services/api'
export default {
Expand All @@ -68,21 +73,29 @@ export default {
return Object.values(this.productSearchForm).every(x => !!x)
}
},
mounted() {
this.productSearchForm.q = this.$route.query[constants.QUERY_PARAM] || ''
if (this.productSearchForm.q) {
this.getProducts()
}
},
methods: {
fieldRequired(v) {
return !!v
},
showBarcodeScannerDialog() {
this.$refs.searchInput.blur()
this.barcodeScannerDialog = true
},
setProductCode(code) {
this.productSearchForm.q = code
this.search()
},
search() {
this.$refs.searchInput.blur()
this.productList = []
this.productTotal = null
this.getProducts()
this.$router.push({ query: { ...this.$route.query, [constants.QUERY_PARAM]: this.productSearchForm.q } })
},
getProducts() {
this.loading = true
Expand Down Expand Up @@ -111,6 +124,13 @@ export default {
}
})
}
},
watch: {
$route (newRoute, oldRoute) { // only called when query changes to avoid having an API call when the path changes
if (oldRoute.path === newRoute.path && JSON.stringify(oldRoute.query) !== JSON.stringify(newRoute.query)) {
this.getProducts()
}
}
}
}
</script>

0 comments on commit edcdf3a

Please sign in to comment.