1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +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 { export interface ServiceMetaDataMarket extends ServiceMetadata {
attributes: MetaDataMarket 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 SearchBar from '../molecules/SearchBar'
import { DID } from '@oceanprotocol/squid' import { DID } from '@oceanprotocol/squid'
import { Link } from 'gatsby' import { Link } from 'gatsby'
import shortid from 'shortid' import shortid from 'shortid'
import axios from 'axios' import { OceanAsset } from '../../@types/MetaData'
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()
}, [])
export default function HomePage({
assets
}: {
assets: {
node: OceanAsset
}[]
}): ReactElement {
return ( return (
<> <>
<SearchBar large /> <SearchBar large />
{assets && ( {assets && (
<ul> <ul>
{assets.map((did: DID) => ( {assets.map(({ node }: { node: { did: DID } }) => (
<li key={shortid.generate()}> <li key={shortid.generate()}>
<Link to={`/asset/${did}`}>{did}</Link> <Link to={`/asset/${node.did}`}>{node.did}</Link>
</li> </li>
))} ))}
</ul> </ul>

View File

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

View File

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