mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
latest assets
This commit is contained in:
parent
8497f6f9a2
commit
a94d7e1b6c
@ -23,7 +23,9 @@ interface HomeProps {
|
|||||||
interface HomeState {
|
interface HomeState {
|
||||||
search?: string
|
search?: string
|
||||||
categoryAssets?: any[]
|
categoryAssets?: any[]
|
||||||
isLoading?: boolean
|
isLoadingCategory?: boolean
|
||||||
|
lastAssets?: any[]
|
||||||
|
isLoadingLast?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const categories =
|
const categories =
|
||||||
@ -36,11 +38,14 @@ class Home extends Component<HomeProps, HomeState> {
|
|||||||
public state = {
|
public state = {
|
||||||
search: '',
|
search: '',
|
||||||
categoryAssets: [],
|
categoryAssets: [],
|
||||||
isLoading: true
|
isLoadingCategory: true,
|
||||||
|
lastAssets: [],
|
||||||
|
isLoadingLast: true
|
||||||
}
|
}
|
||||||
|
|
||||||
public async componentDidMount() {
|
public async componentDidMount() {
|
||||||
this.getCategoryAssets()
|
this.getCategoryAssets()
|
||||||
|
this.getLastAssets()
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCategoryAssets = async () => {
|
private getCategoryAssets = async () => {
|
||||||
@ -62,16 +67,49 @@ class Home extends Component<HomeProps, HomeState> {
|
|||||||
const search = await ocean.aquarius.queryMetadata(searchQuery)
|
const search = await ocean.aquarius.queryMetadata(searchQuery)
|
||||||
this.setState({
|
this.setState({
|
||||||
categoryAssets: search.results,
|
categoryAssets: search.results,
|
||||||
isLoading: false
|
isLoadingCategory: false
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(error.message)
|
Logger.error(error.message)
|
||||||
this.setState({ isLoading: false })
|
this.setState({ isLoadingCategory: false })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getLastAssets = async () => {
|
||||||
|
const { ocean } = this.context
|
||||||
|
ocean.keeper.didRegistry.contract.getPastEvents(
|
||||||
|
'DIDAttributeRegistered',
|
||||||
|
{
|
||||||
|
filter: {},
|
||||||
|
fromBlock: 0,
|
||||||
|
toBlock: 'latest'
|
||||||
|
},
|
||||||
|
async (error: any, events: any) => {
|
||||||
|
if (error) {
|
||||||
|
Logger.log('error retrieving', error)
|
||||||
|
this.setState({ isLoadingLast: false })
|
||||||
|
} else {
|
||||||
|
Logger.log('events retrieving', events)
|
||||||
|
const lastAssets = []
|
||||||
|
// this will tranverse all published assets from latest to first
|
||||||
|
for (const event of events.reverse()) {
|
||||||
|
const ddo = await ocean.assets.resolve(
|
||||||
|
`did:op:${event.returnValues._did.substring(2)}`
|
||||||
|
)
|
||||||
|
// ddo not resolved jump to next ddo
|
||||||
|
if (ddo === null) continue
|
||||||
|
lastAssets.push(ddo)
|
||||||
|
// stop tranversing all events when reaching certain number
|
||||||
|
if (lastAssets.length >= 1) break
|
||||||
|
}
|
||||||
|
this.setState({ lastAssets, isLoadingLast: false })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const { categoryAssets, isLoading, search } = this.state
|
const { categoryAssets, isLoadingCategory, lastAssets, isLoadingLast, search } = this.state
|
||||||
return (
|
return (
|
||||||
<Route
|
<Route
|
||||||
title={meta.title}
|
title={meta.title}
|
||||||
@ -99,7 +137,7 @@ class Home extends Component<HomeProps, HomeState> {
|
|||||||
<Content wide>
|
<Content wide>
|
||||||
<h4>AI for Good</h4>
|
<h4>AI for Good</h4>
|
||||||
<div>
|
<div>
|
||||||
{isLoading ? (
|
{isLoadingCategory ? (
|
||||||
<Spinner message="Loading..." />
|
<Spinner message="Loading..." />
|
||||||
) : categoryAssets && categoryAssets.length ? (
|
) : categoryAssets && categoryAssets.length ? (
|
||||||
<div className={styles.results}>
|
<div className={styles.results}>
|
||||||
@ -111,6 +149,20 @@ class Home extends Component<HomeProps, HomeState> {
|
|||||||
<div>No data sets found.</div>
|
<div>No data sets found.</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
<h4>Latest assets</h4>
|
||||||
|
<div>
|
||||||
|
{isLoadingLast ? (
|
||||||
|
<Spinner message="Loading..." />
|
||||||
|
) : lastAssets && lastAssets.length ? (
|
||||||
|
<div className={styles.results}>
|
||||||
|
{lastAssets.map((asset: any) => (
|
||||||
|
<Asset key={asset.id} asset={asset} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div>No data sets found.</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<h4>Explore Categories</h4>
|
<h4>Explore Categories</h4>
|
||||||
<div className={styles.categories}>
|
<div className={styles.categories}>
|
||||||
{categories.map((category: string) => (
|
{categories.map((category: string) => (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user