1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +01:00

get all assets from GraphQL

This commit is contained in:
Matthias Kretschmann 2020-07-07 10:07:46 +02:00
parent 7cee5eee21
commit 63955639d1
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 34 additions and 22 deletions

View File

@ -23,3 +23,8 @@ export interface MetaDataMarket extends MetaData {
export interface ServiceMetaDataMarket extends ServiceMetadata {
attributes: MetaDataMarket
}
// type for assets pulled into GraphQL
export interface OceanAsset extends MetaDataMarket {
did: DID
}

View File

@ -1,31 +1,25 @@
import React, { ReactElement, useState, useEffect } from 'react'
import React, { ReactElement } from 'react'
import SearchBar from '../molecules/SearchBar'
import { DID } from '@oceanprotocol/squid'
import { Link } from 'gatsby'
import shortid from 'shortid'
import axios from 'axios'
import { config } from '../../config/ocean'
export default function HomePage(): ReactElement {
const [assets, setAssets] = useState<DID[]>()
useEffect(() => {
async function init() {
const result = await axios(`${config.aquariusUri}/api/v1/aquarius/assets`)
const assets = result.data.ids
setAssets(assets)
}
init()
}, [])
import { OceanAsset } from '../../@types/MetaData'
export default function HomePage({
assets
}: {
assets: {
node: OceanAsset
}[]
}): ReactElement {
return (
<>
<SearchBar large />
{assets && (
<ul>
{assets.map((did: DID) => (
{assets.map(({ node }: { node: { did: DID } }) => (
<li key={shortid.generate()}>
<Link to={`/asset/${did}`}>{did}</Link>
<Link to={`/asset/${node.did}`}>{node.did}</Link>
</li>
))}
</ul>

View File

@ -4,11 +4,11 @@ import Layout from '../Layout'
import AssetContent from '../organisms/AssetContent'
export default function AssetDetailsTemplate(props: PageProps): ReactElement {
const { asset } = props.data as any
const { oceanAsset } = props.data as any
return (
<Layout title={asset.main.name} uri={props.path}>
<AssetContent did={asset.did} metadata={asset} />
<Layout title={oceanAsset.main.name} uri={props.path}>
<AssetContent did={oceanAsset.did} metadata={oceanAsset} />
</Layout>
)
}

View File

@ -1,15 +1,28 @@
import React, { ReactElement } from 'react'
import { PageProps } from 'gatsby'
import { PageProps, graphql } from 'gatsby'
import PageHome from '../components/pages/Home'
import { useSiteMetadata } from '../hooks/useSiteMetadata'
import Layout from '../components/Layout'
export default function PageGatsbyHome(props: PageProps): ReactElement {
const { siteTitle, siteTagline } = useSiteMetadata()
const assets = (props.data as any).allOceanAsset.edges
return (
<Layout title={siteTitle} description={siteTagline} uri={props.uri}>
<PageHome />
<PageHome assets={assets} />
</Layout>
)
}
export const pageQuery = graphql`
query PageHomeQuery {
allOceanAsset {
edges {
node {
did
}
}
}
}
`