Skip to content

Commit

Permalink
refactor: new ProductFilterMenu component (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn authored Mar 30, 2024
1 parent 427e97f commit 8dad122
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 35 deletions.
33 changes: 33 additions & 0 deletions src/components/ProductFilterMenu.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<v-menu scroll-strategy="close">
<template v-slot:activator="{ props }">
<v-btn v-bind="props" size="small" class="mr-2" rounded="xl" prepend-icon="mdi-filter-variant" :active="!!productFilter">{{ $t('Common.Filter') }}</v-btn>
</template>
<v-list>
<v-list-item :slim="true" v-for="filter in productFilterList" :key="filter.key" :prepend-icon="(productFilter === filter.key) ? 'mdi-check-circle' : 'mdi-circle-outline'" :active="productFilter === filter.key" @click="selectProductFilter(filter.key)">
{{ $t('Common.' + filter.value) }}
</v-list-item>
</v-list>
</v-menu>
</template>

<script>
import constants from '../constants'
export default {
props: {
'productFilter': String,
},
data() {
return {
productFilterList: constants.PRODUCT_FILTER_LIST,
}
},
emits: ['update:productFilter'],
methods: {
selectProductFilter(filter) {
this.$emit('update:productFilter', filter)
}
}
}
</script>
13 changes: 2 additions & 11 deletions src/views/BrandDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,7 @@

<v-row v-if="!loading">
<v-col>
<v-menu scroll-strategy="close">
<template v-slot:activator="{ props }">
<v-btn v-bind="props" size="small" class="mr-2" prepend-icon="mdi-filter-variant" :active="!!productFilter">{{ $t('Common.Filter') }}</v-btn>
</template>
<v-list>
<v-list-item :slim="true" v-for="filter in productFilterList" :key="filter.key" :prepend-icon="(productFilter === filter.key) ? 'mdi-check-circle' : 'mdi-circle-outline'" :active="productFilter === filter.key" @click="toggleProductFilter(filter.key)">
{{ $t('Common.' + filter.value) }}
</v-list-item>
</v-list>
</v-menu>
<ProductFilterMenu :productFilter="productFilter" @update:productFilter="toggleProductFilter($event)"></ProductFilterMenu>

<v-menu scroll-strategy="close">
<template v-slot:activator="{ props }">
Expand Down Expand Up @@ -74,6 +65,7 @@ import { defineAsyncComponent } from 'vue'
export default {
components: {
'ProductFilterMenu': defineAsyncComponent(() => import('../components/ProductFilterMenu.vue')),
'ProductCard': defineAsyncComponent(() => import('../components/ProductCard.vue')),
'OpenFoodFactsLink': defineAsyncComponent(() => import('../components/OpenFoodFactsLink.vue')),
'ShareButton': defineAsyncComponent(() => import('../components/ShareButton.vue'))
Expand All @@ -82,7 +74,6 @@ export default {
return {
// filter & order
productFilter: '',
productFilterList: constants.PRODUCT_FILTER_LIST,
productOrder: constants.PRODUCT_ORDER_BY_LIST[1].key,
productOrderList: constants.PRODUCT_ORDER_BY_LIST,
// data
Expand Down
13 changes: 2 additions & 11 deletions src/views/CategoryDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,7 @@

<v-row v-if="!loading">
<v-col>
<v-menu scroll-strategy="close">
<template v-slot:activator="{ props }">
<v-btn v-bind="props" size="small" class="mr-2" prepend-icon="mdi-filter-variant" :active="!!productFilter">{{ $t('Common.Filter') }}</v-btn>
</template>
<v-list>
<v-list-item :slim="true" v-for="filter in productFilterList" :key="filter.key" :prepend-icon="(productFilter === filter.key) ? 'mdi-check-circle' : 'mdi-circle-outline'" :active="productFilter === filter.key" @click="toggleProductFilter(filter.key)">
{{ $t('Common.' + filter.value) }}
</v-list-item>
</v-list>
</v-menu>
<ProductFilterMenu :productFilter="productFilter" @update:productFilter="toggleProductFilter($event)"></ProductFilterMenu>

<v-menu scroll-strategy="close">
<template v-slot:activator="{ props }">
Expand Down Expand Up @@ -74,6 +65,7 @@ import { defineAsyncComponent } from 'vue'
export default {
components: {
'ProductFilterMenu': defineAsyncComponent(() => import('../components/ProductFilterMenu.vue')),
'ProductCard': defineAsyncComponent(() => import('../components/ProductCard.vue')),
'OpenFoodFactsLink': defineAsyncComponent(() => import('../components/OpenFoodFactsLink.vue')),
'ShareButton': defineAsyncComponent(() => import('../components/ShareButton.vue'))
Expand All @@ -82,7 +74,6 @@ export default {
return {
// filter & order
productFilter: '',
productFilterList: constants.PRODUCT_FILTER_LIST,
productOrder: constants.PRODUCT_ORDER_BY_LIST[1].key,
productOrderList: constants.PRODUCT_ORDER_BY_LIST,
// data
Expand Down
16 changes: 3 additions & 13 deletions src/views/ProductList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@
<v-chip class="mr-2" label variant="text" prepend-icon="mdi-food-outline">
{{ productTotal }}<span class="d-none d-sm-inline">&nbsp;products</span>
</v-chip>
<ProductFilterMenu :productFilter="productFilter" @update:productFilter="toggleProductFilter($event)"></ProductFilterMenu>
<v-menu scroll-strategy="close">
<template v-slot:activator="{ props }">
<v-btn v-bind="props" size="small" class="mr-2" prepend-icon="mdi-filter-variant" :active="!!productFilter">{{ $t('Common.Filter') }}</v-btn>
</template>
<v-list>
<v-list-item :slim="true" v-for="filter in productFilterList" :key="filter.key" :prepend-icon="(productFilter === filter.key) ? 'mdi-check-circle' : 'mdi-circle-outline'" :active="productFilter === filter.key" @click="toggleProductFilter(filter.key)">
{{ $t('Common.' + filter.value) }}
</v-list-item>
</v-list>
</v-menu>

<v-menu scroll-strategy="close">
<template v-slot:activator="{ props }">
<v-btn v-bind="props" size="small" prepend-icon="mdi-arrow-down" :append-icon="getCurrentProductOrderIcon" :active="!!productOrder">{{ $t('Common.Order') }}</v-btn>
<v-btn v-bind="props" size="small" prepend-icon="mdi-arrow-down" :append-icon="getCurrentProductOrderIcon" :active="!!productOrder">{{ $t('Common.Order') }}</v-btn>
</template>
<v-list>
<v-list-item :slim="true" v-for="order in productOrderList" :key="order.key" :prepend-icon="order.icon" :active="productOrder === order.key" @click="selectProductOrder(order.key)">
Expand Down Expand Up @@ -53,13 +43,13 @@ import { defineAsyncComponent } from 'vue'
export default {
components: {
'ProductFilterMenu': defineAsyncComponent(() => import('../components/ProductFilterMenu.vue')),
'ProductCard': defineAsyncComponent(() => import('../components/ProductCard.vue')),
},
data() {
return {
// filter & order
productFilter: '',
productFilterList: constants.PRODUCT_FILTER_LIST,
productOrder: constants.PRODUCT_ORDER_BY_LIST[1].key,
productOrderList: constants.PRODUCT_ORDER_BY_LIST,
// data
Expand Down

0 comments on commit 8dad122

Please sign in to comment.