mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-15 09:44:53 +01:00
refactor, unify published & consumed list
This commit is contained in:
parent
050b194373
commit
f2cfa49c0e
@ -1,81 +1,34 @@
|
|||||||
import React, { useEffect, useState, ReactElement } from 'react'
|
import React, { useEffect, useState, ReactElement } from 'react'
|
||||||
import Loader from '../atoms/Loader'
|
import Loader from '../atoms/Loader'
|
||||||
import {
|
import { useOcean } from '@oceanprotocol/react'
|
||||||
useOcean,
|
import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore'
|
||||||
OceanConnectionStatus,
|
import AssetList from './AssetList'
|
||||||
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 <DateCell date={row.published} />
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Name',
|
|
||||||
selector: 'name',
|
|
||||||
sortable: true,
|
|
||||||
cell: function getCell(row: any) {
|
|
||||||
return <DdoLinkCell id={row.id} name={row.name} />
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Price',
|
|
||||||
selector: 'price',
|
|
||||||
sortable: true,
|
|
||||||
cell: function getCell(row: any) {
|
|
||||||
return <Price price={fromWei(row.price)} small />
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
export default function ConsumedList(): ReactElement {
|
export default function ConsumedList(): ReactElement {
|
||||||
const { ocean, status, accountId, account } = useOcean()
|
const { ocean, status, accountId } = useOcean()
|
||||||
const [consumedList, setConsumedList] = useState<any>([])
|
const [queryResult, setQueryResult] = useState<QueryResult>()
|
||||||
const { getConsumedList } = useSearch()
|
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getConsumed() {
|
async function getConsumed() {
|
||||||
if (!accountId || !ocean || status !== OceanConnectionStatus.CONNECTED)
|
if (!accountId || !ocean) return
|
||||||
return
|
|
||||||
setIsLoading(true)
|
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)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
getConsumed()
|
getConsumed()
|
||||||
}, [accountId, ocean, status])
|
}, [ocean, status, accountId])
|
||||||
|
|
||||||
return isLoading ? (
|
return isLoading ? (
|
||||||
<Loader />
|
<Loader />
|
||||||
) : account && ocean ? (
|
) : accountId && ocean ? (
|
||||||
<Table data={consumedList} columns={consumedColumns} />
|
<AssetList queryResult={queryResult} />
|
||||||
) : (
|
) : (
|
||||||
<div>Connect your wallet to see your consumed data sets.</div>
|
<div>Connect your wallet to see your published data sets.</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,13 @@ import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/Metadata
|
|||||||
import AssetList from './AssetList'
|
import AssetList from './AssetList'
|
||||||
|
|
||||||
export default function PublishedList(): ReactElement {
|
export default function PublishedList(): ReactElement {
|
||||||
const { ocean, status, account, accountId } = useOcean()
|
const { ocean, status, accountId } = useOcean()
|
||||||
const [queryResult, setQueryResult] = useState<QueryResult>()
|
const [queryResult, setQueryResult] = useState<QueryResult>()
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getPublished() {
|
async function getPublished() {
|
||||||
if (!account || !accountId || !ocean) return
|
if (!accountId || !ocean) return
|
||||||
|
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
|
|
||||||
@ -22,11 +22,11 @@ export default function PublishedList(): ReactElement {
|
|||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
getPublished()
|
getPublished()
|
||||||
}, [accountId, ocean, status])
|
}, [ocean, status, accountId])
|
||||||
|
|
||||||
return isLoading ? (
|
return isLoading ? (
|
||||||
<Loader />
|
<Loader />
|
||||||
) : queryResult ? (
|
) : accountId && ocean ? (
|
||||||
<AssetList queryResult={queryResult} />
|
<AssetList queryResult={queryResult} />
|
||||||
) : (
|
) : (
|
||||||
<div>Connect your wallet to see your published data sets.</div>
|
<div>Connect your wallet to see your published data sets.</div>
|
||||||
|
@ -17,6 +17,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
composes: box from '../atoms/Box.module.css';
|
|
||||||
margin-top: var(--spacer);
|
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);
|
||||||
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import React from 'react'
|
import React, { ReactElement, ReactNode } from 'react'
|
||||||
import styles from './History.module.css'
|
import styles from './History.module.css'
|
||||||
import Web3Feedback from '../molecules/Wallet/Feedback'
|
|
||||||
import ConsumedList from '../organisms/ConsumedList'
|
import ConsumedList from '../organisms/ConsumedList'
|
||||||
import PublishedList from '../organisms/PublishedList'
|
import PublishedList from '../organisms/PublishedList'
|
||||||
import JobsList from '../organisms/JobsList'
|
import JobsList from '../organisms/JobsList'
|
||||||
@ -12,7 +11,7 @@ const sections = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Downloaded',
|
title: 'Downloaded',
|
||||||
component: 'Coming Soon...'
|
component: <ConsumedList />
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Compute Jobs',
|
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 (
|
return (
|
||||||
<div className={styles.section}>
|
<div className={styles.section}>
|
||||||
<h2 className={styles.sectionTitle}>{title}</h2>
|
<h2 className={styles.sectionTitle}>{title}</h2>
|
||||||
@ -29,23 +34,13 @@ const Section = ({ title, component }: { title: string; component: any }) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const HistoryPage: React.FC = () => {
|
export default function HistoryPage(): ReactElement {
|
||||||
return (
|
return (
|
||||||
<article className={styles.grid}>
|
<article className={styles.content}>
|
||||||
<div className={styles.content}>
|
|
||||||
{sections.map((section) => {
|
{sections.map((section) => {
|
||||||
const { title, component } = section
|
const { title, component } = section
|
||||||
return <Section key={title} title={title} component={component} />
|
return <Section key={title} title={title} component={component} />
|
||||||
})}
|
})}
|
||||||
</div>
|
|
||||||
|
|
||||||
<aside>
|
|
||||||
<div className={styles.sticky}>
|
|
||||||
<Web3Feedback />
|
|
||||||
</div>
|
|
||||||
</aside>
|
|
||||||
</article>
|
</article>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default HistoryPage
|
|
||||||
|
Loading…
Reference in New Issue
Block a user