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

View File

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

View File

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