1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

eliminate no price elements on both price filters set

This commit is contained in:
claudia.holhos 2021-02-25 17:10:19 +02:00
parent 2283148e6d
commit 6eaf2efd95
2 changed files with 19 additions and 9 deletions

View File

@ -57,8 +57,8 @@ export default function FilterPrice({
async function handleSelectedFilter(isSelected: boolean, value: string) {
if (
FilterByPriceOptions.Dynamic.includes(value) ||
FilterByPriceOptions.Fixed.includes(value)
value === FilterByPriceOptions.Fixed ||
value === FilterByPriceOptions.Dynamic
) {
if (isSelected) {
if (priceSelections.length > 1) {
@ -75,7 +75,7 @@ export default function FilterPrice({
} else {
if (priceSelections.length) {
// one already selected -> both selected
await applyPriceFilter(undefined)
await applyPriceFilter(FilterByPriceOptions.All)
setPriceSelections(priceFilterItems.map((p) => p.value))
} else {
// none selected -> select

View File

@ -28,7 +28,8 @@ type SortValueOptions = typeof SortValueOptions[keyof typeof SortValueOptions]
export const FilterByPriceOptions = {
Fixed: 'exchange',
Dynamic: 'pool'
Dynamic: 'pool',
All: 'all'
} as const
type FilterByPriceOptions = typeof FilterByPriceOptions[keyof typeof FilterByPriceOptions]
@ -39,11 +40,20 @@ export const FilterByTypeOptions = {
type FilterByTypeOptions = typeof FilterByTypeOptions[keyof typeof FilterByTypeOptions]
function addPriceFilterToQuerry(sortTerm: string, priceFilter: string): string {
sortTerm = priceFilter
? sortTerm === ''
? `price.type:${priceFilter}`
: `${sortTerm} AND price.type:${priceFilter}`
: sortTerm
if (priceFilter === FilterByPriceOptions.All) {
sortTerm = priceFilter
? sortTerm === ''
? `(price.type:${FilterByPriceOptions.Fixed} OR price.type:${FilterByPriceOptions.Dynamic})`
: `${sortTerm} AND (price.type:${FilterByPriceOptions.Dynamic} OR price.type:${FilterByPriceOptions.Fixed})`
: sortTerm
} else {
sortTerm = priceFilter
? sortTerm === ''
? `price.type:${priceFilter}`
: `${sortTerm} AND price.type:${priceFilter}`
: sortTerm
}
console.log('SORT TERM: ', sortTerm)
return sortTerm
}