mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Fix/ Put back filters published page (#867)
* put back filters on published page * fix filter + pagination issue on published asset tab * renamed isSearch prop and made it optional
This commit is contained in:
parent
9b92c524c3
commit
579b213160
@ -2,7 +2,7 @@ import { Logger } from '@oceanprotocol/lib'
|
|||||||
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'
|
||||||
@ -20,11 +20,9 @@ export default function PublishedList({
|
|||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const [page, setPage] = useState<number>(1)
|
const [page, setPage] = useState<number>(1)
|
||||||
const [service, setServiceType] = useState('dataset OR algorithm')
|
const [service, setServiceType] = useState('dataset OR algorithm')
|
||||||
|
const [access, setAccsesType] = useState('access OR compute')
|
||||||
const newCancelToken = useCancelToken()
|
const newCancelToken = useCancelToken()
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!accountId) return
|
|
||||||
|
|
||||||
async function getPublished() {
|
async function getPublished() {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
@ -32,8 +30,9 @@ export default function PublishedList({
|
|||||||
accountId,
|
accountId,
|
||||||
chainIds,
|
chainIds,
|
||||||
newCancelToken(),
|
newCancelToken(),
|
||||||
page - 1,
|
page,
|
||||||
service
|
service,
|
||||||
|
access
|
||||||
)
|
)
|
||||||
setQueryResult(result)
|
setQueryResult(result)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -42,23 +41,35 @@ export default function PublishedList({
|
|||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getPublished()
|
|
||||||
}, [
|
useEffect(() => {
|
||||||
accountId,
|
async function fetchPublishedAssets() {
|
||||||
page,
|
await getPublished()
|
||||||
appConfig.metadataCacheUri,
|
}
|
||||||
chainIds,
|
if (page !== 1) {
|
||||||
service,
|
setPage(1)
|
||||||
newCancelToken
|
} else {
|
||||||
])
|
fetchPublishedAssets()
|
||||||
|
}
|
||||||
|
}, [service, access])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!accountId) return
|
||||||
|
async function fetchPublishedAssets() {
|
||||||
|
await getPublished()
|
||||||
|
}
|
||||||
|
fetchPublishedAssets()
|
||||||
|
}, [accountId, page, appConfig.metadataCacheUri, chainIds, newCancelToken])
|
||||||
|
|
||||||
return accountId ? (
|
return accountId ? (
|
||||||
<>
|
<>
|
||||||
{/* <Filters
|
<Filters
|
||||||
serviceType={service}
|
serviceType={service}
|
||||||
setServiceType={setServiceType}
|
setServiceType={setServiceType}
|
||||||
|
accessType={access}
|
||||||
|
setAccessType={setAccsesType}
|
||||||
className={styles.filters}
|
className={styles.filters}
|
||||||
/> */}
|
/>
|
||||||
<AssetList
|
<AssetList
|
||||||
assets={queryResult?.results}
|
assets={queryResult?.results}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
|
@ -27,18 +27,24 @@ export default function FilterPrice({
|
|||||||
serviceType,
|
serviceType,
|
||||||
accessType,
|
accessType,
|
||||||
setServiceType,
|
setServiceType,
|
||||||
setAccessType
|
setAccessType,
|
||||||
|
addFiltersToUrl,
|
||||||
|
className
|
||||||
}: {
|
}: {
|
||||||
serviceType: string
|
serviceType: string
|
||||||
accessType: string
|
accessType: string
|
||||||
setServiceType: React.Dispatch<React.SetStateAction<string>>
|
setServiceType: React.Dispatch<React.SetStateAction<string>>
|
||||||
setAccessType: React.Dispatch<React.SetStateAction<string>>
|
setAccessType: React.Dispatch<React.SetStateAction<string>>
|
||||||
|
addFiltersToUrl?: boolean
|
||||||
|
className?: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const [serviceSelections, setServiceSelections] = useState<string[]>([])
|
const [serviceSelections, setServiceSelections] = useState<string[]>([])
|
||||||
const [accessSelections, setAccessSelections] = useState<string[]>([])
|
const [accessSelections, setAccessSelections] = useState<string[]>([])
|
||||||
|
|
||||||
async function applyFilter(filter: string, filterType: string) {
|
async function applyFilter(filter: string, filterType: string) {
|
||||||
|
filterType === 'accessType' ? setAccessType(filter) : setServiceType(filter)
|
||||||
|
if (addFiltersToUrl) {
|
||||||
let urlLocation = ''
|
let urlLocation = ''
|
||||||
if (filterType.localeCompare('accessType') === 0) {
|
if (filterType.localeCompare('accessType') === 0) {
|
||||||
urlLocation = await addExistingParamsToUrl(location, ['accessType'])
|
urlLocation = await addExistingParamsToUrl(location, ['accessType'])
|
||||||
@ -52,9 +58,9 @@ export default function FilterPrice({
|
|||||||
: (urlLocation = `${urlLocation}&serviceType=${filter}`)
|
: (urlLocation = `${urlLocation}&serviceType=${filter}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (
|
||||||
@ -109,24 +115,28 @@ export default function FilterPrice({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function applyClearFilter() {
|
async function applyClearFilter(addFiltersToUrl: boolean) {
|
||||||
|
setServiceSelections([])
|
||||||
|
setAccessSelections([])
|
||||||
|
setServiceType(undefined)
|
||||||
|
setAccessType(undefined)
|
||||||
|
if (addFiltersToUrl) {
|
||||||
let urlLocation = await addExistingParamsToUrl(location, [
|
let urlLocation = await addExistingParamsToUrl(location, [
|
||||||
'accessType',
|
'accessType',
|
||||||
'serviceType'
|
'serviceType'
|
||||||
])
|
])
|
||||||
|
|
||||||
urlLocation = `${urlLocation}`
|
urlLocation = `${urlLocation}`
|
||||||
|
|
||||||
setServiceSelections([])
|
|
||||||
setAccessSelections([])
|
|
||||||
|
|
||||||
setServiceType(undefined)
|
|
||||||
setAccessType(undefined)
|
|
||||||
navigate(urlLocation)
|
navigate(urlLocation)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const styleClasses = cx({
|
||||||
|
filterList: true,
|
||||||
|
[className]: className
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.filterList}>
|
<div className={styleClasses}>
|
||||||
{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)
|
||||||
@ -180,7 +190,7 @@ export default function FilterPrice({
|
|||||||
key={index}
|
key={index}
|
||||||
className={showClear ? styles.showClear : styles.hideClear}
|
className={showClear ? styles.showClear : styles.hideClear}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
applyClearFilter()
|
applyClearFilter(addFiltersToUrl)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{e.display}
|
{e.display}
|
||||||
|
@ -77,6 +77,7 @@ export default function SearchPage({
|
|||||||
accessType={access}
|
accessType={access}
|
||||||
setServiceType={setServiceType}
|
setServiceType={setServiceType}
|
||||||
setAccessType={setAccessType}
|
setAccessType={setAccessType}
|
||||||
|
addFiltersToUrl
|
||||||
/>
|
/>
|
||||||
<Sort
|
<Sort
|
||||||
sortType={sortType}
|
sortType={sortType}
|
||||||
|
@ -230,18 +230,20 @@ export async function getPublishedAssets(
|
|||||||
chainIds: number[],
|
chainIds: number[],
|
||||||
cancelToken: CancelToken,
|
cancelToken: CancelToken,
|
||||||
page?: number,
|
page?: number,
|
||||||
type?: string
|
type?: string,
|
||||||
|
accesType?: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
if (!accountId) return
|
if (!accountId) return
|
||||||
|
|
||||||
type = type || 'dataset OR algorithm'
|
type = type || 'dataset OR algorithm'
|
||||||
|
accesType = accesType || 'access OR compute'
|
||||||
|
|
||||||
const queryPublishedAssets = {
|
const queryPublishedAssets = {
|
||||||
from: (Number(page) || 0) * (Number(9) || 21),
|
from: (Number(page) || 0) * (Number(9) || 21),
|
||||||
size: Number(9) || 21,
|
size: Number(9) || 21,
|
||||||
query: {
|
query: {
|
||||||
query_string: {
|
query_string: {
|
||||||
query: `(publicKey.owner:${accountId}) AND (service.attributes.main.type:${type}) AND (${transformChainIdsListToQuery(
|
query: `(publicKey.owner:${accountId}) AND (service.attributes.main.type:${type}) AND (service.type:${accesType}) AND (${transformChainIdsListToQuery(
|
||||||
chainIds
|
chainIds
|
||||||
)})`
|
)})`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user