1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-14 17:24:51 +01:00

spread appConfig into siteMetadata for use in GraphQL

This commit is contained in:
Matthias Kretschmann 2020-07-15 15:09:50 +02:00
parent 42e5ac864f
commit 8c7d2b7891
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 51 additions and 23 deletions

View File

@ -1,10 +1,14 @@
require('dotenv').config() require('dotenv').config()
const siteContent = require('./content/site.json') const siteContent = require('./content/site.json')
const appConfig = require('./app.config')
module.exports = { module.exports = {
siteMetadata: { siteMetadata: {
...siteContent.site ...siteContent.site,
appConfig: {
...appConfig
}
}, },
plugins: [ plugins: [
{ {

View File

@ -6,13 +6,14 @@ import { updateQueryStringParameter } from '../../utils'
import styles from './AssetList.module.css' import styles from './AssetList.module.css'
import { MetaDataMarket } from '../../@types/MetaData' import { MetaDataMarket } from '../../@types/MetaData'
import { DDO } from '@oceanprotocol/lib' import { DDO } from '@oceanprotocol/lib'
import { oceanConfig } from '../../../app.config' import { useSiteMetadata } from '../../hooks/useSiteMetadata'
declare type AssetListProps = { declare type AssetListProps = {
queryResult: QueryResult queryResult: QueryResult
} }
const AssetList: React.FC<AssetListProps> = ({ queryResult }) => { const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
const { appConfig } = useSiteMetadata()
// TODO: restore Pagination behavior // TODO: restore Pagination behavior
// Construct the urls on the pagination links. This is only for UX, // Construct the urls on the pagination links. This is only for UX,
@ -52,7 +53,7 @@ const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
}) })
) : ( ) : (
<div className={styles.empty}> <div className={styles.empty}>
No data sets found in {oceanConfig.metadataStoreUri} No data sets found in {appConfig.oceanConfig.metadataStoreUri}
</div> </div>
)} )}
</div> </div>

View File

@ -1,19 +1,16 @@
import React, { ReactElement, useEffect, useState } from 'react' import React, { ReactElement, useEffect, useState } from 'react'
import SearchBar from '../molecules/SearchBar' import SearchBar from '../molecules/SearchBar'
import styles from './Home.module.css' import styles from './Home.module.css'
import { oceanConfig } from '../../../app.config'
import { MetadataStore, Logger } from '@oceanprotocol/lib' import { MetadataStore, Logger } from '@oceanprotocol/lib'
import AssetList from '../organisms/AssetList' import AssetList from '../organisms/AssetList'
import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore' import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore'
import Container from '../atoms/Container' import Container from '../atoms/Container'
import Loader from '../atoms/Loader' import Loader from '../atoms/Loader'
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
async function getLatestAssets() { async function getLatestAssets(metadataStoreUri: string) {
try { try {
const metadataStore = new MetadataStore( const metadataStore = new MetadataStore(metadataStoreUri, Logger)
oceanConfig.metadataStoreUri,
Logger
)
const result = await metadataStore.queryMetadata({ const result = await metadataStore.queryMetadata({
page: 1, page: 1,
@ -29,12 +26,15 @@ async function getLatestAssets() {
} }
export default function HomePage(): ReactElement { export default function HomePage(): ReactElement {
const { appConfig } = useSiteMetadata()
const [queryResult, setQueryResult] = useState<QueryResult>() const [queryResult, setQueryResult] = useState<QueryResult>()
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
useEffect(() => { useEffect(() => {
async function init() { async function init() {
const results = await getLatestAssets() const results = await getLatestAssets(
appConfig.oceanConfig.metadataStoreUri
)
setQueryResult(results) setQueryResult(results)
setLoading(false) setLoading(false)
} }

View File

@ -2,15 +2,36 @@ import { useStaticQuery, graphql } from 'gatsby'
const query = graphql` const query = graphql`
query { query {
siteMetadata: allFile(filter: { relativePath: { eq: "site.json" } }) { site {
siteMetadata {
siteTitle
siteTagline
siteUrl
siteIcon
copyright
menu {
name
link
}
appConfig {
infuraProjectId
networks
oceanConfig {
factoryAddress
metadataStoreUri
nodeUri
providerUri
verbose
}
}
}
}
siteImage: allFile(filter: { relativePath: { eq: "site.json" } }) {
edges { edges {
node { node {
childContentJson { childContentJson {
site { site {
siteTitle
siteTagline
siteUrl
siteIcon
siteImage { siteImage {
childImageSharp { childImageSharp {
original { original {
@ -18,11 +39,6 @@ const query = graphql`
} }
} }
} }
copyright
menu {
name
link
}
} }
} }
} }
@ -33,5 +49,11 @@ const query = graphql`
export function useSiteMetadata() { export function useSiteMetadata() {
const data = useStaticQuery(query) const data = useStaticQuery(query)
return data.siteMetadata.edges[0].node.childContentJson.site
const siteMeta = {
...data.siteImage.edges[0].node.childContentJson.site,
...data.site.siteMetadata
}
return siteMeta
} }

View File

@ -5,11 +5,12 @@ import Layout from '../../components/Layout'
import { PageProps } from 'gatsby' import { PageProps } from 'gatsby'
import { MetaDataMarket, ServiceMetaDataMarket } from '../../@types/MetaData' import { MetaDataMarket, ServiceMetaDataMarket } from '../../@types/MetaData'
import { MetadataStore, Logger } from '@oceanprotocol/lib' import { MetadataStore, Logger } from '@oceanprotocol/lib'
import { oceanConfig } from '../../../app.config'
import Alert from '../../components/atoms/Alert' import Alert from '../../components/atoms/Alert'
import Loader from '../../components/atoms/Loader' import Loader from '../../components/atoms/Loader'
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
export default function AssetRoute(props: PageProps): ReactElement { export default function AssetRoute(props: PageProps): ReactElement {
const { appConfig } = useSiteMetadata()
const [metadata, setMetadata] = useState<MetaDataMarket>() const [metadata, setMetadata] = useState<MetaDataMarket>()
const [title, setTitle] = useState<string>() const [title, setTitle] = useState<string>()
const [error, setError] = useState<string>() const [error, setError] = useState<string>()
@ -20,7 +21,7 @@ export default function AssetRoute(props: PageProps): ReactElement {
async function init() { async function init() {
try { try {
const metadataStore = new MetadataStore( const metadataStore = new MetadataStore(
oceanConfig.metadataStoreUri, appConfig.oceanConfig.metadataStoreUri,
Logger Logger
) )
const ddo = await metadataStore.retrieveDDO(did) const ddo = await metadataStore.retrieveDDO(did)