mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
price and service filters combined
This commit is contained in:
parent
2eb560b000
commit
ed5796aa42
@ -11,37 +11,52 @@ import Button from '../../atoms/Button'
|
|||||||
|
|
||||||
const cx = classNames.bind(styles)
|
const cx = classNames.bind(styles)
|
||||||
|
|
||||||
const filterItems = [
|
const priceFilterItems = [
|
||||||
{ 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 }
|
||||||
|
]
|
||||||
|
|
||||||
|
const serviceFilterItems = [
|
||||||
{ display: 'data sets', value: FilterByTypeOptions.Data },
|
{ display: 'data sets', value: FilterByTypeOptions.Data },
|
||||||
{ display: 'algorithms', value: FilterByTypeOptions.Algorithm }
|
{ display: 'algorithms', value: FilterByTypeOptions.Algorithm }
|
||||||
]
|
]
|
||||||
|
|
||||||
export default function FilterPrice({
|
export default function FilterPrice({
|
||||||
priceType,
|
priceType,
|
||||||
setPriceType
|
serviceType,
|
||||||
|
setPriceType,
|
||||||
|
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()
|
||||||
|
|
||||||
async function applyFilter(filterBy: string) {
|
async function applyPriceFilter(filterBy: string) {
|
||||||
let urlLocation = await addExistingParamsToUrl(location, 'priceType')
|
let urlLocation = await addExistingParamsToUrl(location, 'priceType')
|
||||||
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 applyServiceFilter(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}>
|
||||||
{filterItems.map((e, index) => {
|
{priceFilterItems.map((e, index) => {
|
||||||
const selectFilter = cx({
|
const selectFilter = cx({
|
||||||
[styles.selected]: e.value === priceType,
|
[styles.selected]: e.value === priceType,
|
||||||
[styles.filter]: true
|
[styles.filter]: true
|
||||||
@ -56,10 +71,36 @@ export default function FilterPrice({
|
|||||||
onClick={
|
onClick={
|
||||||
isSelected
|
isSelected
|
||||||
? async () => {
|
? async () => {
|
||||||
await applyFilter(undefined)
|
await applyPriceFilter(undefined)
|
||||||
}
|
}
|
||||||
: async () => {
|
: async () => {
|
||||||
await applyFilter(e.value)
|
await applyPriceFilter(e.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{e.display}
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
{serviceFilterItems.map((e, index) => {
|
||||||
|
const selectFilter = cx({
|
||||||
|
[styles.selected]: e.value === serviceType,
|
||||||
|
[styles.filter]: true
|
||||||
|
})
|
||||||
|
const isSelected = e.value === serviceType
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
style="text"
|
||||||
|
key={index}
|
||||||
|
className={selectFilter}
|
||||||
|
onClick={
|
||||||
|
isSelected
|
||||||
|
? async () => {
|
||||||
|
await applyServiceFilter(undefined)
|
||||||
|
}
|
||||||
|
: async () => {
|
||||||
|
await applyServiceFilter(e.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
@ -34,7 +34,7 @@ export default function SearchPage({
|
|||||||
const [queryResult, setQueryResult] = useState<QueryResult>()
|
const [queryResult, setQueryResult] = useState<QueryResult>()
|
||||||
const [loading, setLoading] = useState<boolean>()
|
const [loading, setLoading] = useState<boolean>()
|
||||||
const [price, setPriceType] = useState<string>(priceType as string)
|
const [price, setPriceType] = useState<string>(priceType as string)
|
||||||
const [type, setType] = useState<string>(serviceType as string)
|
const [service, setServiceType] = useState<string>(serviceType as string)
|
||||||
const [sortType, setSortType] = useState<string>(sort as string)
|
const [sortType, setSortType] = useState<string>(sort as string)
|
||||||
const [sortDirection, setSortDirection] = useState<string>(
|
const [sortDirection, setSortDirection] = useState<string>(
|
||||||
sortOrder as string
|
sortOrder as string
|
||||||
@ -82,9 +82,9 @@ export default function SearchPage({
|
|||||||
<div className={styles.row}>
|
<div className={styles.row}>
|
||||||
<PriceFilter
|
<PriceFilter
|
||||||
priceType={price}
|
priceType={price}
|
||||||
|
serviceType={service}
|
||||||
setPriceType={setPriceType}
|
setPriceType={setPriceType}
|
||||||
serviceType={type}
|
setServiceType={setServiceType}
|
||||||
setServiceType={setType}
|
|
||||||
/>
|
/>
|
||||||
<Sort
|
<Sort
|
||||||
sortType={sortType}
|
sortType={sortType}
|
||||||
@ -92,6 +92,7 @@ export default function SearchPage({
|
|||||||
setSortType={setSortType}
|
setSortType={setSortType}
|
||||||
setSortDirection={setSortDirection}
|
setSortDirection={setSortDirection}
|
||||||
setPriceType={setPriceType}
|
setPriceType={setPriceType}
|
||||||
|
setServiceType={setServiceType}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -24,13 +24,15 @@ export default function Sort({
|
|||||||
setSortType,
|
setSortType,
|
||||||
sortDirection,
|
sortDirection,
|
||||||
setSortDirection,
|
setSortDirection,
|
||||||
setPriceType
|
setPriceType,
|
||||||
|
setServiceType
|
||||||
}: {
|
}: {
|
||||||
sortType: string
|
sortType: string
|
||||||
setSortType: React.Dispatch<React.SetStateAction<string>>
|
setSortType: React.Dispatch<React.SetStateAction<string>>
|
||||||
sortDirection: string
|
sortDirection: string
|
||||||
setSortDirection: React.Dispatch<React.SetStateAction<string>>
|
setSortDirection: React.Dispatch<React.SetStateAction<string>>
|
||||||
setPriceType: React.Dispatch<React.SetStateAction<string>>
|
setPriceType: React.Dispatch<React.SetStateAction<string>>
|
||||||
|
setServiceType: React.Dispatch<React.SetStateAction<string>>
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const directionArrow = String.fromCharCode(
|
const directionArrow = String.fromCharCode(
|
||||||
|
Loading…
Reference in New Issue
Block a user