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

roll back search filter refactor for published list

This commit is contained in:
Matthias Kretschmann 2021-09-15 12:28:35 +02:00
parent eacd0c56a0
commit 15a29bcb01
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 138 additions and 162 deletions

View File

@ -3,7 +3,7 @@ import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatacache/Metadata
import React, { ReactElement, useEffect, useState } from 'react'
import AssetList from '../../../organisms/AssetList'
import { getPublishedAssets } from '../../../../utils/aquarius'
import Filters from '../../../templates/Search/Filters'
// import Filters from '../../../templates/Search/Filters'
import { useSiteMetadata } from '../../../../hooks/useSiteMetadata'
import { useUserPreferences } from '../../../../providers/UserPreferences'
import styles from './PublishedList.module.css'
@ -53,12 +53,11 @@ export default function PublishedList({
return accountId ? (
<>
<Filters
{/* <Filters
serviceType={service}
setServiceType={setServiceType}
isSearch={false}
className={styles.filters}
/>
/> */}
<AssetList
assets={queryResult?.results}
isLoading={isLoading}

View File

@ -23,20 +23,16 @@ const accessFilterItems = [
{ display: 'compute ', value: FilterByAccessOptions.Compute }
]
export default function Filters({
export default function FilterPrice({
serviceType,
accessType,
setServiceType,
setAccessType,
isSearch,
className
setAccessType
}: {
serviceType: string
accessType: string
setServiceType: React.Dispatch<React.SetStateAction<string>>
isSearch: boolean
setAccessType: React.Dispatch<React.SetStateAction<string>>
className?: string
}): ReactElement {
const navigate = useNavigate()
const [serviceSelections, setServiceSelections] = useState<string[]>([])
@ -50,27 +46,15 @@ export default function Filters({
urlLocation = await addExistingParamsToUrl(location, ['serviceType'])
}
async function applyServiceFilter(filterBy: string) {
setServiceType(filterBy)
if (filter && location.search.indexOf(filterType) === -1) {
filterType === 'accessType'
? (urlLocation = `${urlLocation}&accessType=${filter}`)
: (urlLocation = `${urlLocation}&serviceType=${filter}`)
}
if (isSearch) {
let urlLocation = await addExistingParamsToUrl(location, [
'serviceType'
])
if (filterBy && location.search.indexOf('&serviceType') === -1) {
urlLocation = `${urlLocation}&serviceType=${filterBy}`
}
filterType === 'accessType'
? setAccessType(filter)
: setServiceType(filter)
filterType === 'accessType' ? setAccessType(filter) : setServiceType(filter)
navigate(urlLocation)
}
}
async function handleSelectedFilter(isSelected: boolean, value: string) {
if (
@ -125,32 +109,27 @@ export default function Filters({
}
}
async function applyClearFilter(isSearch: boolean) {
async function applyClearFilter() {
let urlLocation = await addExistingParamsToUrl(location, [
'accessType',
'serviceType'
])
urlLocation = `${urlLocation}`
setServiceSelections([])
setAccessSelections([])
setServiceType(undefined)
setAccessType(undefined)
if (isSearch) {
let urlLocation = await addExistingParamsToUrl(location, [
'serviceType'
])
urlLocation = `${urlLocation}`
navigate(urlLocation)
}
}
const styleClasses = cx({
filterList: true,
[className]: className
})
return (
<div className={styleClasses}>
<div className={styles.filterList}>
{serviceFilterItems.map((e, index) => {
const isServiceSelected =
e.value === serviceType || serviceSelections.includes(e.value)
const selectFilter = cx({
[styles.selected]: isServiceSelected,
[styles.filter]: true
@ -201,7 +180,7 @@ export default function Filters({
key={index}
className={showClear ? styles.showClear : styles.hideClear}
onClick={async () => {
applyClearFilter(isSearch)
applyClearFilter()
}}
>
{e.display}
@ -211,4 +190,3 @@ export default function Filters({
</div>
)
}
}

View File

@ -80,7 +80,6 @@ export default function SearchPage({
accessType={access}
setServiceType={setServiceType}
setAccessType={setAccessType}
isSearch
/>
<Sort
sortType={sortType}