mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
AI for good frontpage, cleanup
This commit is contained in:
parent
9f782adafc
commit
90c4590a8b
@ -31,6 +31,11 @@ interface ChannelState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class Channel extends PureComponent<ChannelProps, ChannelState> {
|
export default class Channel extends PureComponent<ChannelProps, ChannelState> {
|
||||||
|
// get content data based on received channel param
|
||||||
|
public channel = channels.items
|
||||||
|
.filter(({ slug }) => slug === this.props.match.params.channel)
|
||||||
|
.map(channel => channel)[0]
|
||||||
|
|
||||||
public state = {
|
public state = {
|
||||||
results: [],
|
results: [],
|
||||||
totalResults: 0,
|
totalResults: 0,
|
||||||
@ -38,13 +43,8 @@ export default class Channel extends PureComponent<ChannelProps, ChannelState> {
|
|||||||
totalPages: 1,
|
totalPages: 1,
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
// get content data based on received channel param
|
title: this.channel.title,
|
||||||
title: channels
|
description: this.channel.description
|
||||||
.filter(({ slug }) => slug === this.props.match.params.channel)
|
|
||||||
.map(channel => channel)[0].title,
|
|
||||||
description: channels
|
|
||||||
.filter(({ slug }) => slug === this.props.match.params.channel)
|
|
||||||
.map(channel => channel)[0].description
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async componentDidMount() {
|
public async componentDidMount() {
|
||||||
|
@ -3,6 +3,7 @@ import Helmet from 'react-helmet'
|
|||||||
import Content from '../atoms/Content'
|
import Content from '../atoms/Content'
|
||||||
import styles from './Route.module.scss'
|
import styles from './Route.module.scss'
|
||||||
import meta from '../../data/meta.json'
|
import meta from '../../data/meta.json'
|
||||||
|
import Markdown from '../atoms/Markdown'
|
||||||
|
|
||||||
const Route = ({
|
const Route = ({
|
||||||
title,
|
title,
|
||||||
@ -29,11 +30,9 @@ const Route = ({
|
|||||||
<Content wide={wide}>
|
<Content wide={wide}>
|
||||||
<h1 className={styles.title}>{title}</h1>
|
<h1 className={styles.title}>{title}</h1>
|
||||||
{description && (
|
{description && (
|
||||||
<p
|
<Markdown
|
||||||
|
text={description}
|
||||||
className={styles.description}
|
className={styles.description}
|
||||||
dangerouslySetInnerHTML={{
|
|
||||||
__html: description
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Content>
|
</Content>
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
import React, { PureComponent } from 'react'
|
import React, { PureComponent } from 'react'
|
||||||
import { Logger, Ocean } from '@oceanprotocol/squid'
|
import { Logger, Ocean } from '@oceanprotocol/squid'
|
||||||
import { Market } from '.'
|
import { Market } from '.'
|
||||||
|
import formPublish from '../data/form-publish.json'
|
||||||
|
|
||||||
|
const categories =
|
||||||
|
(formPublish.steps[1].fields &&
|
||||||
|
formPublish.steps[1].fields.categories &&
|
||||||
|
formPublish.steps[1].fields.categories.options) ||
|
||||||
|
[]
|
||||||
|
|
||||||
interface MarketProviderProps {
|
interface MarketProviderProps {
|
||||||
ocean: Ocean
|
ocean: Ocean
|
||||||
@ -8,6 +15,7 @@ interface MarketProviderProps {
|
|||||||
|
|
||||||
interface MarketProviderState {
|
interface MarketProviderState {
|
||||||
totalAssets: number
|
totalAssets: number
|
||||||
|
categories: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class MarketProvider extends PureComponent<
|
export default class MarketProvider extends PureComponent<
|
||||||
@ -15,7 +23,8 @@ export default class MarketProvider extends PureComponent<
|
|||||||
MarketProviderState
|
MarketProviderState
|
||||||
> {
|
> {
|
||||||
public state = {
|
public state = {
|
||||||
totalAssets: 0
|
totalAssets: 0,
|
||||||
|
categories
|
||||||
}
|
}
|
||||||
|
|
||||||
public async componentDidMount() {}
|
public async componentDidMount() {}
|
||||||
|
@ -22,4 +22,4 @@ export const User = React.createContext({
|
|||||||
message: ''
|
message: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
export const Market = React.createContext({ totalAssets: 0 })
|
export const Market = React.createContext({ totalAssets: 0, categories: [''] })
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
[
|
{
|
||||||
{
|
"title": "Channels",
|
||||||
"title": "AI for Good",
|
"description": "Channels are... You can do this with them... They're cool because...",
|
||||||
"slug": "ai-for-good",
|
"items": [
|
||||||
"description": "AI for Good is an initiative to promote the use of artificial intelligence for good causes, such as fighting poverty, climate change, improving healthcare, safer transportation, and so on. The AI for Good Global Summit is THE leading United Nations platform for global and inclusive dialogue on AI. The Summit is hosted each year in Geneva by the ITU in partnership wutg UN Suster agencies, XPRIZE Foundtation and ACM."
|
{
|
||||||
},
|
"title": "AI for Good",
|
||||||
{
|
"slug": "ai-for-good",
|
||||||
"title": "Test Channel",
|
"teaser": "AI for Good is an initiative to promote the use of artificial intelligence for good causes.",
|
||||||
"slug": "test-channel",
|
"description": "AI for Good is an initiative to promote the use of artificial intelligence for good causes, such as fighting poverty, climate change, improving healthcare, safer transportation, and so on. The [AI for Good Global Summit](https://aiforgood.itu.int) is the leading United Nations platform for global and inclusive dialogue on AI. The Summit is hosted each year in Geneva by the ITU in partnership with UN Sister agencies, XPRIZE Foundation and ACM."
|
||||||
"description": "Hello description."
|
},
|
||||||
}
|
{
|
||||||
]
|
"title": "Test Channel",
|
||||||
|
"slug": "test-channel",
|
||||||
|
"description": "Hello description."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
@ -7,10 +7,10 @@ import { Link } from 'react-router-dom'
|
|||||||
class Channels extends Component {
|
class Channels extends Component {
|
||||||
public render() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
<Route title="Channels" description="All the Channels.">
|
<Route title={channels.title} description={channels.description}>
|
||||||
<Content>
|
<Content>
|
||||||
<ul>
|
<ul>
|
||||||
{channels.map(channel => (
|
{channels.items.map(channel => (
|
||||||
<li key={channel.title}>
|
<li key={channel.title}>
|
||||||
<Link to={`/channels/${channel.slug}`}>
|
<Link to={`/channels/${channel.slug}`}>
|
||||||
{channel.title}
|
{channel.title}
|
||||||
|
@ -14,21 +14,53 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.results {
|
.channel {
|
||||||
|
width: 100%;
|
||||||
|
padding-top: $spacer * 2;
|
||||||
|
|
||||||
|
@media (min-width: $break-point--medium) {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
> div {
|
||||||
|
&:first-child {
|
||||||
|
margin-right: $spacer;
|
||||||
|
margin-bottom: $spacer;
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: $break-point--medium) {
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
&:first-child {
|
||||||
|
flex: 0 0 24.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-size: $font-size-h4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.channelTitle {
|
||||||
|
margin-top: $spacer * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channelResults {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
grid-gap: $spacer;
|
grid-gap: $spacer;
|
||||||
max-width: calc(18rem + #{$spacer * 2});
|
|
||||||
margin: auto;
|
|
||||||
|
|
||||||
@media (min-width: $break-point--small) {
|
@media (min-width: $break-point--small) {
|
||||||
margin: 0;
|
|
||||||
max-width: none;
|
|
||||||
grid-template-columns: repeat(2, 1fr);
|
grid-template-columns: repeat(2, 1fr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: $break-point--medium) {
|
> article {
|
||||||
grid-template-columns: repeat(3, 1fr);
|
min-width: calc(18rem + #{$spacer * 2.3});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React, { ChangeEvent, Component, FormEvent } from 'react'
|
import React, { ChangeEvent, Component, FormEvent } from 'react'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { User } from '../context'
|
import { User, Market } from '../context'
|
||||||
import { Logger } from '@oceanprotocol/squid'
|
import { Logger } from '@oceanprotocol/squid'
|
||||||
import Spinner from '../components/atoms/Spinner'
|
import Spinner from '../components/atoms/Spinner'
|
||||||
import Asset from '../components/molecules/Asset'
|
import Asset from '../components/molecules/Asset'
|
||||||
@ -12,14 +12,16 @@ import Route from '../components/templates/Route'
|
|||||||
import styles from './Home.module.scss'
|
import styles from './Home.module.scss'
|
||||||
|
|
||||||
import meta from '../data/meta.json'
|
import meta from '../data/meta.json'
|
||||||
import formPublish from '../data/form-publish.json'
|
|
||||||
import { History } from 'history'
|
import { History } from 'history'
|
||||||
import Content from '../components/atoms/Content'
|
import Content from '../components/atoms/Content'
|
||||||
import channels from '../data/channels.json'
|
import channels from '../data/channels.json'
|
||||||
import AssetsLatest from '../components/organisms/AssetsLatest'
|
import AssetsLatest from '../components/organisms/AssetsLatest'
|
||||||
|
|
||||||
// AI for Good channel
|
// AI for Good channel
|
||||||
const { title, slug } = channels[0]
|
const channel = channels.items
|
||||||
|
.filter(({ slug }) => slug === 'ai-for-good')
|
||||||
|
.map(channel => channel)[0]
|
||||||
|
const { title, slug, teaser } = channel
|
||||||
|
|
||||||
interface HomeProps {
|
interface HomeProps {
|
||||||
history: History
|
history: History
|
||||||
@ -27,40 +29,32 @@ interface HomeProps {
|
|||||||
|
|
||||||
interface HomeState {
|
interface HomeState {
|
||||||
search?: string
|
search?: string
|
||||||
categoryAssets?: any[]
|
channelAssets?: any[]
|
||||||
isLoadingCategory?: boolean
|
isLoadingChannel?: boolean
|
||||||
latestAssets?: any[]
|
|
||||||
isLoadingLatest?: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const categories =
|
|
||||||
(formPublish.steps[1].fields &&
|
|
||||||
formPublish.steps[1].fields.categories &&
|
|
||||||
formPublish.steps[1].fields.categories.options) ||
|
|
||||||
[]
|
|
||||||
|
|
||||||
export default class Home extends Component<HomeProps, HomeState> {
|
export default class Home extends Component<HomeProps, HomeState> {
|
||||||
public static contextType = User
|
public static contextType = User
|
||||||
|
|
||||||
public state = {
|
public state = {
|
||||||
search: '',
|
search: '',
|
||||||
categoryAssets: [],
|
channelAssets: [],
|
||||||
isLoadingCategory: true,
|
isLoadingChannel: true
|
||||||
latestAssets: [],
|
|
||||||
isLoadingLatest: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async componentDidMount() {
|
public async componentDidMount() {
|
||||||
this.getCategoryAssets()
|
this.getChannelAssets()
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCategoryAssets = async () => {
|
private getChannelAssets = async () => {
|
||||||
const { ocean } = this.context
|
const { ocean } = this.context
|
||||||
|
|
||||||
const searchQuery = {
|
const searchQuery = {
|
||||||
offset: 25,
|
offset: 4,
|
||||||
page: 1,
|
page: 1,
|
||||||
query: {
|
query: {
|
||||||
|
// TODO: remove dummy category
|
||||||
|
// categories: [title],
|
||||||
categories: ['Engineering'],
|
categories: ['Engineering'],
|
||||||
price: [-1, 1]
|
price: [-1, 1]
|
||||||
},
|
},
|
||||||
@ -72,12 +66,12 @@ export default class Home extends Component<HomeProps, HomeState> {
|
|||||||
try {
|
try {
|
||||||
const search = await ocean.aquarius.queryMetadata(searchQuery)
|
const search = await ocean.aquarius.queryMetadata(searchQuery)
|
||||||
this.setState({
|
this.setState({
|
||||||
categoryAssets: search.results,
|
channelAssets: search.results,
|
||||||
isLoadingCategory: false
|
isLoadingChannel: false
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(error.message)
|
Logger.error(error.message)
|
||||||
this.setState({ isLoadingCategory: false })
|
this.setState({ isLoadingChannel: false })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +87,7 @@ export default class Home extends Component<HomeProps, HomeState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const { categoryAssets, isLoadingCategory, search } = this.state
|
const { channelAssets, isLoadingChannel, search } = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Route
|
<Route
|
||||||
@ -120,21 +114,30 @@ export default class Home extends Component<HomeProps, HomeState> {
|
|||||||
</Content>
|
</Content>
|
||||||
|
|
||||||
<Content wide>
|
<Content wide>
|
||||||
<h2 className={styles.title}>
|
<div className={styles.channel}>
|
||||||
<Link to={`/channels/${slug}`}>{title}</Link>
|
<div>
|
||||||
</h2>
|
<div>
|
||||||
<div>
|
<h2 className={styles.channelTitle}>
|
||||||
{isLoadingCategory ? (
|
<Link to={`/channels/${slug}`}>
|
||||||
<Spinner message="Loading..." />
|
{title} →
|
||||||
) : categoryAssets && categoryAssets.length ? (
|
</Link>
|
||||||
<div className={styles.results}>
|
</h2>
|
||||||
{categoryAssets.map((asset: any) => (
|
<p>{teaser}</p>
|
||||||
<Asset key={asset.id} asset={asset} />
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
) : (
|
</div>
|
||||||
<div>No data sets found.</div>
|
<div>
|
||||||
)}
|
{isLoadingChannel ? (
|
||||||
|
<Spinner message="Loading..." />
|
||||||
|
) : channelAssets && channelAssets.length ? (
|
||||||
|
<div className={styles.channelResults}>
|
||||||
|
{channelAssets.map((asset: any) => (
|
||||||
|
<Asset key={asset.id} asset={asset} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div>No data sets found.</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AssetsLatest />
|
<AssetsLatest />
|
||||||
@ -143,19 +146,27 @@ export default class Home extends Component<HomeProps, HomeState> {
|
|||||||
<Content>
|
<Content>
|
||||||
<h2 className={styles.title}>Explore Categories</h2>
|
<h2 className={styles.title}>Explore Categories</h2>
|
||||||
<div className={styles.categories}>
|
<div className={styles.categories}>
|
||||||
{categories
|
<Market.Consumer>
|
||||||
.filter(category => category !== 'AI For Good')
|
{({ categories }) =>
|
||||||
.sort((a, b) => a.localeCompare(b))
|
categories
|
||||||
.map((category: string) => (
|
.filter(
|
||||||
<Link
|
category => category !== 'AI For Good'
|
||||||
to={`/search?categories=${category}`}
|
)
|
||||||
key={category}
|
.sort((a, b) => a.localeCompare(b)) // sort alphabetically
|
||||||
className={styles.category}
|
.map((category: string) => (
|
||||||
>
|
<Link
|
||||||
<CategoryImage category={category} />
|
to={`/search?categories=${category}`}
|
||||||
<h3>{category}</h3>
|
key={category}
|
||||||
</Link>
|
className={styles.category}
|
||||||
))}
|
>
|
||||||
|
<CategoryImage
|
||||||
|
category={category}
|
||||||
|
/>
|
||||||
|
<h3>{category}</h3>
|
||||||
|
</Link>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</Market.Consumer>
|
||||||
</div>
|
</div>
|
||||||
</Content>
|
</Content>
|
||||||
</Route>
|
</Route>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user