feat: filter by categories in market
This commit is contained in:
parent
22e32c9513
commit
50b8c654ae
2 changed files with 18 additions and 6 deletions
|
|
@ -13,7 +13,8 @@ async function customerMarket(path) {
|
||||||
'update-stalls',
|
'update-stalls',
|
||||||
'styles',
|
'styles',
|
||||||
|
|
||||||
'search-text'
|
'search-text',
|
||||||
|
'filter-categories'
|
||||||
],
|
],
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
|
|
@ -32,22 +33,26 @@ async function customerMarket(path) {
|
||||||
},
|
},
|
||||||
products: function () {
|
products: function () {
|
||||||
this.refreshProducts()
|
this.refreshProducts()
|
||||||
|
},
|
||||||
|
filterCategories: function () {
|
||||||
|
console.log('### watch filterCategories')
|
||||||
|
this.refreshProducts()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
refreshProducts: function() {
|
refreshProducts: function () {
|
||||||
this.showProducts = false
|
this.showProducts = false
|
||||||
const searchText = this.searchText?.toLowerCase() || ''
|
const searchText = this.searchText?.toLowerCase() || ''
|
||||||
this.partialProducts = []
|
this.partialProducts = []
|
||||||
|
this.filteredProducts = this.products.filter(p => this.hasCategory(p.categories))
|
||||||
if (searchText.length < 3) {
|
if (searchText.length < 3) {
|
||||||
this.filteredProducts = [...this.products]
|
|
||||||
this.lastProductIndex = Math.min(this.filteredProducts.length, this.productsPerPage)
|
this.lastProductIndex = Math.min(this.filteredProducts.length, this.productsPerPage)
|
||||||
this.partialProducts.push(...this.filteredProducts.slice(0, this.lastProductIndex))
|
this.partialProducts.push(...this.filteredProducts.slice(0, this.lastProductIndex))
|
||||||
setTimeout(() => this.showProducts = true, 0)
|
setTimeout(() => this.showProducts = true, 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.filteredProducts = this.products.filter(p => {
|
this.filteredProducts = this.products.filter(p => {
|
||||||
return (
|
return (
|
||||||
p.name.toLowerCase().includes(searchText) ||
|
p.name.toLowerCase().includes(searchText) ||
|
||||||
|
|
@ -63,6 +68,13 @@ async function customerMarket(path) {
|
||||||
|
|
||||||
setTimeout(() => { this.showProducts = true }, 0)
|
setTimeout(() => { this.showProducts = true }, 0)
|
||||||
},
|
},
|
||||||
|
hasCategory(categories = []) {
|
||||||
|
if (!this.filterCategories?.length) return true
|
||||||
|
for (const cat of categories) {
|
||||||
|
if (this.filterCategories.indexOf(cat) !== -1) return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
addToCart(item) {
|
addToCart(item) {
|
||||||
this.$emit('add-to-cart', item)
|
this.$emit('add-to-cart', item)
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -278,8 +278,8 @@
|
||||||
:product-detail="activeProduct" :relays="relays" :account="account" :pool="pool" :styles="config?.opts ?? {}"
|
:product-detail="activeProduct" :relays="relays" :account="account" :pool="pool" :styles="config?.opts ?? {}"
|
||||||
@login-dialog="openAccountDialog" @change-page="navigateTo" @add-to-cart="addProductToCart"></customer-stall>
|
@login-dialog="openAccountDialog" @change-page="navigateTo" @add-to-cart="addProductToCart"></customer-stall>
|
||||||
<customer-market v-else :search-nostr="searchNostr" :relays="relays" :products="products"
|
<customer-market v-else :search-nostr="searchNostr" :relays="relays" :products="products"
|
||||||
:search-text="searchText" :styles="config?.opts ?? {}" @change-page="navigateTo" @update-data="updateData"
|
:search-text="searchText" :filter-categories="filterCategories" :styles="config?.opts ?? {}"
|
||||||
@add-to-cart="addProductToCart"></customer-market>
|
@change-page="navigateTo" @update-data="updateData" @add-to-cart="addProductToCart"></customer-market>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-2 col-md-1 col-sm-0 auto-width"></div>
|
<div class="col-lg-2 col-md-1 col-sm-0 auto-width"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue