From f2cfa49c0eeaf725f1cd713595d093376d4b5b10 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 3 Sep 2020 10:35:26 +0200 Subject: [PATCH] refactor, unify published & consumed list --- src/components/organisms/ConsumedList.tsx | 73 ++++------------------ src/components/organisms/PublishedList.tsx | 8 +-- src/components/pages/History.module.css | 15 ++++- src/components/pages/History.tsx | 35 +++++------ 4 files changed, 46 insertions(+), 85 deletions(-) diff --git a/src/components/organisms/ConsumedList.tsx b/src/components/organisms/ConsumedList.tsx index d0f1ba573..de7160dd6 100644 --- a/src/components/organisms/ConsumedList.tsx +++ b/src/components/organisms/ConsumedList.tsx @@ -1,81 +1,34 @@ import React, { useEffect, useState, ReactElement } from 'react' import Loader from '../atoms/Loader' -import { - useOcean, - OceanConnectionStatus, - useSearch -} from '@oceanprotocol/react' -import Table from '../atoms/Table' -import Price from '../atoms/Price' -import { fromWei } from 'web3-utils' -import DateCell from '../atoms/Table/DateCell' -import DdoLinkCell from '../atoms/Table/DdoLinkCell' -import { MetadataMain } from '@oceanprotocol/lib' - -const consumedColumns = [ - { - name: 'Published', - selector: 'published', - sortable: true, - cell: function getCell(row: any) { - return - } - }, - { - name: 'Name', - selector: 'name', - sortable: true, - cell: function getCell(row: any) { - return - } - }, - { - name: 'Price', - selector: 'price', - sortable: true, - cell: function getCell(row: any) { - return - } - } -] +import { useOcean } from '@oceanprotocol/react' +import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore' +import AssetList from './AssetList' export default function ConsumedList(): ReactElement { - const { ocean, status, accountId, account } = useOcean() - const [consumedList, setConsumedList] = useState([]) - const { getConsumedList } = useSearch() + const { ocean, status, accountId } = useOcean() + const [queryResult, setQueryResult] = useState() const [isLoading, setIsLoading] = useState(false) useEffect(() => { async function getConsumed() { - if (!accountId || !ocean || status !== OceanConnectionStatus.CONNECTED) - return + if (!accountId || !ocean) return + setIsLoading(true) - const consumedItems = await getConsumedList() + // const queryResult = await - if (!consumedItems) return + setQueryResult(queryResult) - const data = consumedItems.map((ddo) => { - const { attributes } = ddo.findServiceByType('metadata') - const { name, price, datePublished } = attributes.main as MetadataMain - return { - published: datePublished, - name: name, - price: price - } - }) - - setConsumedList(data) setIsLoading(false) } getConsumed() - }, [accountId, ocean, status]) + }, [ocean, status, accountId]) return isLoading ? ( - ) : account && ocean ? ( - + ) : accountId && ocean ? ( + ) : ( -
Connect your wallet to see your consumed data sets.
+
Connect your wallet to see your published data sets.
) } diff --git a/src/components/organisms/PublishedList.tsx b/src/components/organisms/PublishedList.tsx index 228dc7dcf..9b131eaf0 100644 --- a/src/components/organisms/PublishedList.tsx +++ b/src/components/organisms/PublishedList.tsx @@ -5,13 +5,13 @@ import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/Metadata import AssetList from './AssetList' export default function PublishedList(): ReactElement { - const { ocean, status, account, accountId } = useOcean() + const { ocean, status, accountId } = useOcean() const [queryResult, setQueryResult] = useState() const [isLoading, setIsLoading] = useState(false) useEffect(() => { async function getPublished() { - if (!account || !accountId || !ocean) return + if (!accountId || !ocean) return setIsLoading(true) @@ -22,11 +22,11 @@ export default function PublishedList(): ReactElement { setIsLoading(false) } getPublished() - }, [accountId, ocean, status]) + }, [ocean, status, accountId]) return isLoading ? ( - ) : queryResult ? ( + ) : accountId && ocean ? ( ) : (
Connect your wallet to see your published data sets.
diff --git a/src/components/pages/History.module.css b/src/components/pages/History.module.css index 0c947b6af..7b7528dde 100644 --- a/src/components/pages/History.module.css +++ b/src/components/pages/History.module.css @@ -17,6 +17,19 @@ } .content { - composes: box from '../atoms/Box.module.css'; margin-top: var(--spacer); } + +.section { + composes: box from '../atoms/Box.module.css'; + margin-bottom: var(--spacer); +} + +.section:last-child { + margin-bottom: 0; +} + +.sectionTitle { + font-size: var(--font-size-h3); + margin-bottom: calc(var(--spacer) / 2); +} diff --git a/src/components/pages/History.tsx b/src/components/pages/History.tsx index 29c8257a5..a6faf8991 100644 --- a/src/components/pages/History.tsx +++ b/src/components/pages/History.tsx @@ -1,6 +1,5 @@ -import React from 'react' +import React, { ReactElement, ReactNode } from 'react' import styles from './History.module.css' -import Web3Feedback from '../molecules/Wallet/Feedback' import ConsumedList from '../organisms/ConsumedList' import PublishedList from '../organisms/PublishedList' import JobsList from '../organisms/JobsList' @@ -12,7 +11,7 @@ const sections = [ }, { title: 'Downloaded', - component: 'Coming Soon...' + component: }, { title: 'Compute Jobs', @@ -20,7 +19,13 @@ const sections = [ } ] -const Section = ({ title, component }: { title: string; component: any }) => { +const Section = ({ + title, + component +}: { + title: string + component: ReactNode +}) => { return (

{title}

@@ -29,23 +34,13 @@ const Section = ({ title, component }: { title: string; component: any }) => { ) } -const HistoryPage: React.FC = () => { +export default function HistoryPage(): ReactElement { return ( -
-
- {sections.map((section) => { - const { title, component } = section - return
- })} -
- - +
+ {sections.map((section) => { + const { title, component } = section + return
+ })}
) } - -export default HistoryPage