fix: filter products at top level
This commit is contained in:
parent
50b8c654ae
commit
3a94405124
3 changed files with 15 additions and 26 deletions
|
|
@ -5,7 +5,7 @@ async function customerMarket(path) {
|
||||||
template,
|
template,
|
||||||
|
|
||||||
props: [
|
props: [
|
||||||
'products',
|
'filtered-products',
|
||||||
'change-page',
|
'change-page',
|
||||||
'search-nostr',
|
'search-nostr',
|
||||||
'relays',
|
'relays',
|
||||||
|
|
@ -20,7 +20,6 @@ async function customerMarket(path) {
|
||||||
return {
|
return {
|
||||||
search: null,
|
search: null,
|
||||||
partialProducts: [],
|
partialProducts: [],
|
||||||
filteredProducts: [],
|
|
||||||
productsPerPage: 12,
|
productsPerPage: 12,
|
||||||
startIndex: 0,
|
startIndex: 0,
|
||||||
lastProductIndex: 0,
|
lastProductIndex: 0,
|
||||||
|
|
@ -31,11 +30,10 @@ async function customerMarket(path) {
|
||||||
searchText: function () {
|
searchText: function () {
|
||||||
this.refreshProducts()
|
this.refreshProducts()
|
||||||
},
|
},
|
||||||
products: function () {
|
filteredProducts: function () {
|
||||||
this.refreshProducts()
|
this.refreshProducts()
|
||||||
},
|
},
|
||||||
filterCategories: function () {
|
filterCategories: function () {
|
||||||
console.log('### watch filterCategories')
|
|
||||||
this.refreshProducts()
|
this.refreshProducts()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -44,7 +42,7 @@ async function customerMarket(path) {
|
||||||
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.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))
|
||||||
|
|
@ -52,29 +50,13 @@ async function customerMarket(path) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.filteredProducts = this.products.filter(p => {
|
|
||||||
return (
|
|
||||||
p.name.toLowerCase().includes(searchText) ||
|
|
||||||
(p.description &&
|
|
||||||
p.description.toLowerCase().includes(searchText)) ||
|
|
||||||
(p.categories &&
|
|
||||||
p.categories.toString().toLowerCase().includes(searchText))
|
|
||||||
)
|
|
||||||
})
|
|
||||||
this.startIndex = 0
|
this.startIndex = 0
|
||||||
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)
|
||||||
},
|
},
|
||||||
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)
|
||||||
},
|
},
|
||||||
|
|
@ -122,7 +104,6 @@ async function customerMarket(path) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.filteredProducts = [...this.products]
|
|
||||||
this.lastProductIndex = Math.min(this.filteredProducts.length, 24)
|
this.lastProductIndex = Math.min(this.filteredProducts.length, 24)
|
||||||
this.partialProducts.push(...this.filteredProducts.slice(0, this.lastProductIndex))
|
this.partialProducts.push(...this.filteredProducts.slice(0, this.lastProductIndex))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ const market = async () => {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
filterProducts() {
|
filterProducts() {
|
||||||
let products = this.products
|
let products = this.products.filter(p => this.hasCategory(p.categories))
|
||||||
if (this.activeStall) {
|
if (this.activeStall) {
|
||||||
products = products.filter(p => p.stall_id == this.activeStall)
|
products = products.filter(p => p.stall_id == this.activeStall)
|
||||||
}
|
}
|
||||||
|
|
@ -891,7 +891,15 @@ const market = async () => {
|
||||||
} else {
|
} else {
|
||||||
this.filterCategories.splice(index, 1)
|
this.filterCategories.splice(index, 1)
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
|
hasCategory(categories = []) {
|
||||||
|
if (!this.filterCategories?.length) return true
|
||||||
|
for (const cat of categories) {
|
||||||
|
if (this.filterCategories.indexOf(cat) !== -1) return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -277,7 +277,7 @@
|
||||||
:products="filterProducts" :stall-products="products.filter(p => p.stall_id == activeStall)"
|
:products="filterProducts" :stall-products="products.filter(p => p.stall_id == activeStall)"
|
||||||
: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" :filtered-products="filterProducts"
|
||||||
:search-text="searchText" :filter-categories="filterCategories" :styles="config?.opts ?? {}"
|
:search-text="searchText" :filter-categories="filterCategories" :styles="config?.opts ?? {}"
|
||||||
@change-page="navigateTo" @update-data="updateData" @add-to-cart="addProductToCart"></customer-market>
|
@change-page="navigateTo" @update-data="updateData" @add-to-cart="addProductToCart"></customer-market>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue