From a36e32aa4ba6239a078fa4821d7df8d19862d2d1 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Fri, 20 Aug 2021 16:30:38 +0300 Subject: [PATCH 1/5] added sort for published assets --- .../pages/Account/History/PublishedList.tsx | 38 ++++++++++++------- .../templates/Search/filterService.tsx | 30 ++++++++------- src/components/templates/Search/index.tsx | 1 + 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/components/pages/Account/History/PublishedList.tsx b/src/components/pages/Account/History/PublishedList.tsx index 2a6f5996c..5f8fad32a 100644 --- a/src/components/pages/Account/History/PublishedList.tsx +++ b/src/components/pages/Account/History/PublishedList.tsx @@ -1,13 +1,13 @@ import { Logger } from '@oceanprotocol/lib' 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 axios from 'axios' import { queryMetadata, transformChainIdsListToQuery } from '../../../../utils/aquarius' -import { useWeb3 } from '../../../../providers/Web3' +import ServiceFilter from '../../../templates/Search/filterService' import { useSiteMetadata } from '../../../../hooks/useSiteMetadata' import { useUserPreferences } from '../../../../providers/UserPreferences' @@ -22,16 +22,19 @@ export default function PublishedList({ const [queryResult, setQueryResult] = useState() const [isLoading, setIsLoading] = useState(false) const [page, setPage] = useState(1) + const [service, setServiceType] = useState() useEffect(() => { async function getPublished() { + const serviceFiter = + service === undefined ? 'dataset OR algorithm' : `${service}` if (!accountId) return const queryPublishedAssets = { page: page, offset: 9, query: { query_string: { - query: `(publicKey.owner:${accountId}) AND (${transformChainIdsListToQuery( + query: `(publicKey.owner:${accountId}) AND (service.attributes.main.type:${serviceFiter}) AND (${transformChainIdsListToQuery( chainIds )})` } @@ -51,19 +54,26 @@ export default function PublishedList({ } } getPublished() - }, [accountId, page, appConfig.metadataCacheUri, chainIds]) + }, [accountId, page, appConfig.metadataCacheUri, chainIds, service]) return accountId ? ( - { - setPage(newPage) - }} - /> +
+ + { + setPage(newPage) + }} + /> +
) : (
Please connect your Web3 wallet.
) diff --git a/src/components/templates/Search/filterService.tsx b/src/components/templates/Search/filterService.tsx index 168c35fe2..888996be7 100644 --- a/src/components/templates/Search/filterService.tsx +++ b/src/components/templates/Search/filterService.tsx @@ -16,21 +16,25 @@ const serviceFilterItems = [ export default function FilterPrice({ serviceType, - setServiceType + setServiceType, + isSearch }: { serviceType: string setServiceType: React.Dispatch> + isSearch: boolean }): ReactElement { const navigate = useNavigate() const [serviceSelections, setServiceSelections] = useState([]) async function applyServiceFilter(filterBy: string) { - let urlLocation = await addExistingParamsToUrl(location, ['serviceType']) - if (filterBy && location.search.indexOf('&serviceType') === -1) { - urlLocation = `${urlLocation}&serviceType=${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) { @@ -58,14 +62,14 @@ export default function FilterPrice({ } } - async function applyClearFilter() { - let urlLocation = await addExistingParamsToUrl(location, ['serviceType']) - - urlLocation = `${urlLocation}` - + async function applyClearFilter(isSearch: boolean) { setServiceSelections([]) setServiceType(undefined) - navigate(urlLocation) + if (isSearch) { + let urlLocation = await addExistingParamsToUrl(location, ['serviceType']) + urlLocation = `${urlLocation}` + navigate(urlLocation) + } } return ( @@ -100,7 +104,7 @@ export default function FilterPrice({ key={index} className={showClear ? styles.showClear : styles.hideClear} onClick={async () => { - applyClearFilter() + applyClearFilter(isSearch) }} > {e.display} diff --git a/src/components/templates/Search/index.tsx b/src/components/templates/Search/index.tsx index 2f9508b41..d61aed559 100644 --- a/src/components/templates/Search/index.tsx +++ b/src/components/templates/Search/index.tsx @@ -75,6 +75,7 @@ export default function SearchPage({ Date: Fri, 20 Aug 2021 16:45:53 +0300 Subject: [PATCH 2/5] fixed lint error --- src/components/templates/Search/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/templates/Search/index.tsx b/src/components/templates/Search/index.tsx index d61aed559..fc11f2218 100644 --- a/src/components/templates/Search/index.tsx +++ b/src/components/templates/Search/index.tsx @@ -75,7 +75,7 @@ export default function SearchPage({ Date: Mon, 23 Aug 2021 12:11:28 +0300 Subject: [PATCH 3/5] display filter only when necessary --- .../pages/Account/History/PublishedList.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/pages/Account/History/PublishedList.tsx b/src/components/pages/Account/History/PublishedList.tsx index 5f8fad32a..c2610aa2c 100644 --- a/src/components/pages/Account/History/PublishedList.tsx +++ b/src/components/pages/Account/History/PublishedList.tsx @@ -58,11 +58,16 @@ export default function PublishedList({ return accountId ? (
- + {queryResult?.results?.length > 0 ? ( + + ) : ( + '' + )} + Date: Mon, 23 Aug 2021 16:17:28 +0300 Subject: [PATCH 4/5] display loading spinner on every fetch published assets call --- src/components/pages/Account/History/PublishedList.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/pages/Account/History/PublishedList.tsx b/src/components/pages/Account/History/PublishedList.tsx index c2610aa2c..f03ca89ce 100644 --- a/src/components/pages/Account/History/PublishedList.tsx +++ b/src/components/pages/Account/History/PublishedList.tsx @@ -44,7 +44,7 @@ export default function PublishedList({ try { const source = axios.CancelToken.source() - queryResult || setIsLoading(true) + setIsLoading(true) const result = await queryMetadata(queryPublishedAssets, source.token) setQueryResult(result) } catch (error) { From 18badb7b17c5c7ef556cdb31a0588699f9e3d732 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Tue, 24 Aug 2021 16:55:32 +0300 Subject: [PATCH 5/5] allways display filters on published page --- .../pages/Account/History/PublishedList.tsx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/components/pages/Account/History/PublishedList.tsx b/src/components/pages/Account/History/PublishedList.tsx index f03ca89ce..c9f4cda3c 100644 --- a/src/components/pages/Account/History/PublishedList.tsx +++ b/src/components/pages/Account/History/PublishedList.tsx @@ -58,16 +58,11 @@ export default function PublishedList({ return accountId ? (
- {queryResult?.results?.length > 0 ? ( - - ) : ( - '' - )} - +