mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
select and deselect filter button
This commit is contained in:
parent
ce81777030
commit
2eb560b000
@ -11,28 +11,20 @@ import Button from '../../atoms/Button'
|
|||||||
|
|
||||||
const cx = classNames.bind(styles)
|
const cx = classNames.bind(styles)
|
||||||
|
|
||||||
const filterItemsPrice = [
|
const filterItems = [
|
||||||
{ display: 'all', value: undefined },
|
{ display: 'all', value: undefined },
|
||||||
{ display: 'fixed price', value: FilterByPriceOptions.Fixed },
|
{ display: 'fixed price', value: FilterByPriceOptions.Fixed },
|
||||||
{ display: 'dynamic price', value: FilterByPriceOptions.Dynamic }
|
{ display: 'dynamic price', value: FilterByPriceOptions.Dynamic },
|
||||||
]
|
{ display: 'data sets', value: FilterByTypeOptions.Data },
|
||||||
|
{ display: 'algorithms', value: FilterByTypeOptions.Algorithm }
|
||||||
const filterItemsType = [
|
|
||||||
{ display: 'all', value: undefined },
|
|
||||||
{ display: 'algorithms', value: FilterByTypeOptions.Algorithm },
|
|
||||||
{ display: 'data sets', value: FilterByTypeOptions.Data }
|
|
||||||
]
|
]
|
||||||
|
|
||||||
export default function FilterPrice({
|
export default function FilterPrice({
|
||||||
priceType,
|
priceType,
|
||||||
setPriceType,
|
setPriceType
|
||||||
serviceType,
|
|
||||||
setServiceType
|
|
||||||
}: {
|
}: {
|
||||||
priceType: string
|
priceType: string
|
||||||
setPriceType: React.Dispatch<React.SetStateAction<string>>
|
setPriceType: React.Dispatch<React.SetStateAction<string>>
|
||||||
serviceType: string
|
|
||||||
setServiceType: React.Dispatch<React.SetStateAction<string>>
|
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
@ -41,57 +33,35 @@ export default function FilterPrice({
|
|||||||
if (filterBy) {
|
if (filterBy) {
|
||||||
urlLocation = `${urlLocation}&priceType=${filterBy}`
|
urlLocation = `${urlLocation}&priceType=${filterBy}`
|
||||||
}
|
}
|
||||||
|
console.log('FILTER BY: ', filterBy)
|
||||||
setPriceType(filterBy)
|
setPriceType(filterBy)
|
||||||
navigate(urlLocation)
|
navigate(urlLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function applyTypeFilter(filterBy: string) {
|
|
||||||
let urlLocation = await addExistingParamsToUrl(location, 'serviceType')
|
|
||||||
if (filterBy) {
|
|
||||||
urlLocation = `${urlLocation}&serviceType=${filterBy}`
|
|
||||||
}
|
|
||||||
setServiceType(filterBy)
|
|
||||||
navigate(urlLocation)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className={styles.filterList}>
|
<div className={styles.filterList}>
|
||||||
{filterItemsType.map((e, index) => {
|
{filterItems.map((e, index) => {
|
||||||
const filter = cx({
|
const selectFilter = cx({
|
||||||
[styles.selected]: e.value === serviceType,
|
|
||||||
[styles.filter]: true
|
|
||||||
})
|
|
||||||
return (
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
style="text"
|
|
||||||
key={index}
|
|
||||||
className={filter}
|
|
||||||
onClick={async () => {
|
|
||||||
await applyTypeFilter(e.value)
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{e.display}
|
|
||||||
</Button>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
<div className={styles.filterList}>
|
|
||||||
{filterItemsPrice.map((e, index) => {
|
|
||||||
const filter = cx({
|
|
||||||
[styles.selected]: e.value === priceType,
|
[styles.selected]: e.value === priceType,
|
||||||
[styles.filter]: true
|
[styles.filter]: true
|
||||||
})
|
})
|
||||||
|
const isSelected = e.value === priceType
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
style="text"
|
style="text"
|
||||||
key={index}
|
key={index}
|
||||||
className={filter}
|
className={selectFilter}
|
||||||
onClick={async () => {
|
onClick={
|
||||||
await applyFilter(e.value)
|
isSelected
|
||||||
}}
|
? async () => {
|
||||||
|
await applyFilter(undefined)
|
||||||
|
}
|
||||||
|
: async () => {
|
||||||
|
await applyFilter(e.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{e.display}
|
{e.display}
|
||||||
</Button>
|
</Button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user