mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
simplify PublishedList
This commit is contained in:
parent
f80f93489b
commit
050b194373
@ -1,87 +1,24 @@
|
|||||||
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 { MetadataMain } from '@oceanprotocol/lib'
|
import { useOcean } from '@oceanprotocol/react'
|
||||||
import {
|
import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore'
|
||||||
useOcean,
|
import AssetList from './AssetList'
|
||||||
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'
|
|
||||||
|
|
||||||
const publishedColumns = [
|
|
||||||
{
|
|
||||||
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 PublishedList(): ReactElement {
|
export default function PublishedList(): ReactElement {
|
||||||
const { ocean, status, account, accountId } = useOcean()
|
const { ocean, status, account, accountId } = useOcean()
|
||||||
const { getPublishedList } = useSearch()
|
const [queryResult, setQueryResult] = useState<QueryResult>()
|
||||||
const [publishedList, setPublishedList] = useState<any[]>([])
|
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const [paginationParams, setPaginationParams] = useState({
|
|
||||||
count: 1,
|
|
||||||
rowsPerPage: 10,
|
|
||||||
page: 1
|
|
||||||
})
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getPublished() {
|
async function getPublished() {
|
||||||
if (
|
if (!account || !accountId || !ocean) return
|
||||||
!account ||
|
|
||||||
!accountId ||
|
|
||||||
!ocean ||
|
|
||||||
status !== OceanConnectionStatus.CONNECTED
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
const publishedItems = await getPublishedList(
|
|
||||||
paginationParams.page,
|
|
||||||
paginationParams.rowsPerPage
|
|
||||||
)
|
|
||||||
setPaginationParams({
|
|
||||||
...paginationParams,
|
|
||||||
count: publishedItems.totalPages
|
|
||||||
})
|
|
||||||
|
|
||||||
const data = publishedItems.results.map((ddo) => {
|
// const queryResult = await
|
||||||
const { attributes } = ddo.findServiceByType('metadata')
|
|
||||||
const { name, price, datePublished } = attributes.main as MetadataMain
|
setQueryResult(queryResult)
|
||||||
return {
|
|
||||||
published: datePublished,
|
|
||||||
name: name,
|
|
||||||
price: price,
|
|
||||||
id: ddo.id
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
setPublishedList(data)
|
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
getPublished()
|
getPublished()
|
||||||
@ -89,8 +26,8 @@ export default function PublishedList(): ReactElement {
|
|||||||
|
|
||||||
return isLoading ? (
|
return isLoading ? (
|
||||||
<Loader />
|
<Loader />
|
||||||
) : account && ocean ? (
|
) : queryResult ? (
|
||||||
<Table data={publishedList} columns={publishedColumns} />
|
<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>
|
||||||
)
|
)
|
||||||
|
@ -8,7 +8,7 @@ import JobsList from '../organisms/JobsList'
|
|||||||
const sections = [
|
const sections = [
|
||||||
{
|
{
|
||||||
title: 'Published',
|
title: 'Published',
|
||||||
component: 'Coming Soon...'
|
component: <PublishedList />
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Downloaded',
|
title: 'Downloaded',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user