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

Merge pull request #805 from oceanprotocol/issue710-account-published-page

Account history published page
This commit is contained in:
Bogdan Fazakas 2021-08-25 08:58:56 +03:00 committed by GitHub
commit ffb9c45764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 28 deletions

View File

@ -1,13 +1,13 @@
import { Logger } from '@oceanprotocol/lib' import { Logger } from '@oceanprotocol/lib'
import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatacache/MetadataCache' import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatacache/MetadataCache'
import React, { ReactElement, useEffect, useState } from 'react' import React, { ReactElement, useEffect, useState, useReducer } from 'react'
import AssetList from '../../../organisms/AssetList' import AssetList from '../../../organisms/AssetList'
import axios from 'axios' import axios from 'axios'
import { import {
queryMetadata, queryMetadata,
transformChainIdsListToQuery transformChainIdsListToQuery
} from '../../../../utils/aquarius' } from '../../../../utils/aquarius'
import { useWeb3 } from '../../../../providers/Web3' import ServiceFilter from '../../../templates/Search/filterService'
import { useSiteMetadata } from '../../../../hooks/useSiteMetadata' import { useSiteMetadata } from '../../../../hooks/useSiteMetadata'
import { useUserPreferences } from '../../../../providers/UserPreferences' import { useUserPreferences } from '../../../../providers/UserPreferences'
@ -22,16 +22,19 @@ export default function PublishedList({
const [queryResult, setQueryResult] = useState<QueryResult>() const [queryResult, setQueryResult] = useState<QueryResult>()
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<string>()
useEffect(() => { useEffect(() => {
async function getPublished() { async function getPublished() {
const serviceFiter =
service === undefined ? 'dataset OR algorithm' : `${service}`
if (!accountId) return if (!accountId) return
const queryPublishedAssets = { const queryPublishedAssets = {
page: page, page: page,
offset: 9, offset: 9,
query: { query: {
query_string: { query_string: {
query: `(publicKey.owner:${accountId}) AND (${transformChainIdsListToQuery( query: `(publicKey.owner:${accountId}) AND (service.attributes.main.type:${serviceFiter}) AND (${transformChainIdsListToQuery(
chainIds chainIds
)})` )})`
} }
@ -41,7 +44,7 @@ export default function PublishedList({
try { try {
const source = axios.CancelToken.source() const source = axios.CancelToken.source()
queryResult || setIsLoading(true) setIsLoading(true)
const result = await queryMetadata(queryPublishedAssets, source.token) const result = await queryMetadata(queryPublishedAssets, source.token)
setQueryResult(result) setQueryResult(result)
} catch (error) { } catch (error) {
@ -51,19 +54,26 @@ export default function PublishedList({
} }
} }
getPublished() getPublished()
}, [accountId, page, appConfig.metadataCacheUri, chainIds]) }, [accountId, page, appConfig.metadataCacheUri, chainIds, service])
return accountId ? ( return accountId ? (
<AssetList <div>
assets={queryResult?.results} <ServiceFilter
isLoading={isLoading} serviceType={service}
showPagination setServiceType={setServiceType}
page={queryResult?.page} isSearch={false}
totalPages={queryResult?.totalPages} />
onPageChange={(newPage) => { <AssetList
setPage(newPage) assets={queryResult?.results}
}} isLoading={isLoading}
/> showPagination
page={queryResult?.page}
totalPages={queryResult?.totalPages}
onPageChange={(newPage) => {
setPage(newPage)
}}
/>
</div>
) : ( ) : (
<div>Please connect your Web3 wallet.</div> <div>Please connect your Web3 wallet.</div>
) )

View File

@ -16,21 +16,25 @@ const serviceFilterItems = [
export default function FilterPrice({ export default function FilterPrice({
serviceType, serviceType,
setServiceType setServiceType,
isSearch
}: { }: {
serviceType: string serviceType: string
setServiceType: React.Dispatch<React.SetStateAction<string>> setServiceType: React.Dispatch<React.SetStateAction<string>>
isSearch: boolean
}): ReactElement { }): ReactElement {
const navigate = useNavigate() const navigate = useNavigate()
const [serviceSelections, setServiceSelections] = useState<string[]>([]) const [serviceSelections, setServiceSelections] = useState<string[]>([])
async function applyServiceFilter(filterBy: string) { async function applyServiceFilter(filterBy: string) {
let urlLocation = await addExistingParamsToUrl(location, ['serviceType'])
if (filterBy && location.search.indexOf('&serviceType') === -1) {
urlLocation = `${urlLocation}&serviceType=${filterBy}`
}
setServiceType(filterBy) setServiceType(filterBy)
navigate(urlLocation) if (isSearch) {
let urlLocation = await addExistingParamsToUrl(location, ['serviceType'])
if (filterBy && location.search.indexOf('&serviceType') === -1) {
urlLocation = `${urlLocation}&serviceType=${filterBy}`
}
navigate(urlLocation)
}
} }
async function handleSelectedFilter(isSelected: boolean, value: string) { async function handleSelectedFilter(isSelected: boolean, value: string) {
@ -58,14 +62,14 @@ export default function FilterPrice({
} }
} }
async function applyClearFilter() { async function applyClearFilter(isSearch: boolean) {
let urlLocation = await addExistingParamsToUrl(location, ['serviceType'])
urlLocation = `${urlLocation}`
setServiceSelections([]) setServiceSelections([])
setServiceType(undefined) setServiceType(undefined)
navigate(urlLocation) if (isSearch) {
let urlLocation = await addExistingParamsToUrl(location, ['serviceType'])
urlLocation = `${urlLocation}`
navigate(urlLocation)
}
} }
return ( return (
@ -100,7 +104,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(isSearch)
}} }}
> >
{e.display} {e.display}

View File

@ -75,6 +75,7 @@ export default function SearchPage({
<ServiceFilter <ServiceFilter
serviceType={service} serviceType={service}
setServiceType={setServiceType} setServiceType={setServiceType}
isSearch
/> />
<Sort <Sort
sortType={sortType} sortType={sortType}