1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

new channel termplate, channels route, use json data for everything

This commit is contained in:
Matthias Kretschmann 2019-05-23 14:43:40 +02:00
parent 3199d89d8d
commit 9f782adafc
Signed by: m
GPG Key ID: 606EEEF3C479A91F
8 changed files with 75 additions and 61 deletions

View File

@ -10,12 +10,14 @@ import Publish from './routes/Publish/'
import Search from './routes/Search' import Search from './routes/Search'
import Faucet from './routes/Faucet' import Faucet from './routes/Faucet'
import History from './routes/History' import History from './routes/History'
import Channel from './routes/Channel' import Channels from './routes/Channels'
import Styleguide from './routes/Styleguide' import Styleguide from './routes/Styleguide'
import Channel from './components/templates/Channel'
const Routes = () => ( const Routes = () => (
<Switch> <Switch>
<Route exact component={withTracker(Home)} path="/" /> <Route component={withTracker(Home)} exact path="/" />
<Route component={withTracker(Styleguide)} path="/styleguide" /> <Route component={withTracker(Styleguide)} path="/styleguide" />
<Route component={withTracker(About)} path="/about" /> <Route component={withTracker(About)} path="/about" />
<Route component={withTracker(Publish)} path="/publish" /> <Route component={withTracker(Publish)} path="/publish" />
@ -23,6 +25,7 @@ const Routes = () => (
<Route component={withTracker(Details)} path="/asset/:did" /> <Route component={withTracker(Details)} path="/asset/:did" />
<Route component={withTracker(Faucet)} path="/faucet" /> <Route component={withTracker(Faucet)} path="/faucet" />
<Route component={withTracker(History)} path="/history" /> <Route component={withTracker(History)} path="/history" />
<Route component={withTracker(Channels)} exact path="/channels" />
<Route component={withTracker(Channel)} path="/channels/:channel" /> <Route component={withTracker(Channel)} path="/channels/:channel" />
<Route component={withTracker(NotFound)} /> <Route component={withTracker(NotFound)} />
</Switch> </Switch>

View File

@ -1,4 +1,4 @@
@import '../styles/variables'; @import '../../styles/variables';
.results { .results {
display: grid; display: grid;

View File

@ -1,7 +1,7 @@
import React from 'react' import React from 'react'
import { render } from 'react-testing-library' import { render } from 'react-testing-library'
import Channel from './Channel' import Channel from './Channel'
import { User } from '../context' import { User } from '../../context'
import { createMemoryHistory } from 'history' import { createMemoryHistory } from 'history'
describe('Channel', () => { describe('Channel', () => {
@ -36,11 +36,8 @@ describe('Channel', () => {
}} }}
> >
<Channel <Channel
location={{ match={{
search: '', params: { channel: 'ai-for-good' }
pathname: '/channel/AI for Good',
state: '',
hash: ''
}} }}
history={history} history={history}
/> />

View File

@ -1,23 +1,21 @@
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import queryString from 'query-string'
import { History, Location } from 'history'
import { Logger } from '@oceanprotocol/squid' import { Logger } from '@oceanprotocol/squid'
import Spinner from '../components/atoms/Spinner' import { History } from 'history'
import Route from '../components/templates/Route' import Spinner from '../../components/atoms/Spinner'
import { User } from '../context' import Route from '../../components/templates/Route'
import Asset from '../components/molecules/Asset' import { User } from '../../context'
import Pagination from '../components/molecules/Pagination' import Asset from '../../components/molecules/Asset'
import Pagination from '../../components/molecules/Pagination'
import styles from './Channel.module.scss' import styles from './Channel.module.scss'
import Content from '../components/atoms/Content' import Content from '../../components/atoms/Content'
import channels from '../data/channels.json' import channels from '../../data/channels.json'
const { title, description } = channels[0]
interface ChannelProps { interface ChannelProps {
location: Location
history: History history: History
match: { match: {
params: any params: {
channel: string
}
} }
} }
@ -28,8 +26,8 @@ interface ChannelState {
totalPages: number totalPages: number
currentPage: number currentPage: number
isLoading: boolean isLoading: boolean
searchTerm: string title: string
searchCategories: string description: string
} }
export default class Channel extends PureComponent<ChannelProps, ChannelState> { export default class Channel extends PureComponent<ChannelProps, ChannelState> {
@ -40,50 +38,30 @@ export default class Channel extends PureComponent<ChannelProps, ChannelState> {
totalPages: 1, totalPages: 1,
currentPage: 1, currentPage: 1,
isLoading: true, isLoading: true,
searchTerm: '', // get content data based on received channel param
searchCategories: '' title: channels
.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() {
const { match } = this.props
// TODO: use next line to use channel name
// const category = match.params.channel
const category = 'Engineering'
const { page } = queryString.parse(this.props.location.search)
if (category) {
await this.setState({
searchCategories: encodeURIComponent(`${category}`)
})
}
// switch to respective page if query string is present
if (page) {
const currentPage = Number(page)
await this.setState({ currentPage })
}
this.getChannelAssets() this.getChannelAssets()
} }
private getChannelAssets = async () => { private getChannelAssets = async () => {
const { ocean } = this.context const { ocean } = this.context
const { offset, currentPage, searchTerm, searchCategories } = this.state const { offset, currentPage } = this.state
const queryValues =
searchCategories !== '' && searchTerm !== ''
? { text: [searchTerm], categories: [searchCategories] }
: searchCategories !== '' && searchTerm === ''
? { categories: [searchCategories] }
: { text: [searchTerm] }
const searchQuery = { const searchQuery = {
offset, offset,
page: currentPage, page: currentPage,
query: { query: {
...queryValues, // TODO: replace dummy category
// categories: [this.state.title],
categories: ['Engineering'],
price: [-1, 1] price: [-1, 1]
}, },
sort: { sort: {
@ -110,8 +88,7 @@ export default class Channel extends PureComponent<ChannelProps, ChannelState> {
let toPage = data.selected + 1 let toPage = data.selected + 1
this.props.history.push({ this.props.history.push({
pathname: this.props.location.pathname, search: `?page=${toPage}`
search: `?text=${this.state.searchTerm}&page=${toPage}`
}) })
await this.setState({ currentPage: toPage, isLoading: true }) await this.setState({ currentPage: toPage, isLoading: true })
@ -132,7 +109,7 @@ export default class Channel extends PureComponent<ChannelProps, ChannelState> {
) )
public render() { public render() {
const { totalPages, currentPage } = this.state const { title, description, totalPages, currentPage } = this.state
return ( return (
<Route title={title} description={description}> <Route title={title} description={description}>

View File

@ -1,6 +1,12 @@
[ [
{ {
"title": "AI for Good", "title": "AI for Good",
"slug": "ai-for-good",
"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." "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": "Test Channel",
"slug": "test-channel",
"description": "Hello description."
} }
] ]

View File

@ -1,4 +1,8 @@
[ [
{
"title": "Channels",
"link": "/channels"
},
{ {
"title": "Publish", "title": "Publish",
"link": "/publish" "link": "/publish"

View File

@ -0,0 +1,27 @@
import React, { Component } from 'react'
import Route from '../components/templates/Route'
import Content from '../components/atoms/Content'
import channels from '../data/channels.json'
import { Link } from 'react-router-dom'
class Channels extends Component {
public render() {
return (
<Route title="Channels" description="All the Channels.">
<Content>
<ul>
{channels.map(channel => (
<li key={channel.title}>
<Link to={`/channels/${channel.slug}`}>
{channel.title}
</Link>
</li>
))}
</ul>
</Content>
</Route>
)
}
}
export default Channels

View File

@ -1,6 +1,5 @@
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 slugify from '@sindresorhus/slugify'
import { User } from '../context' import { User } from '../context'
import { Logger } from '@oceanprotocol/squid' import { Logger } from '@oceanprotocol/squid'
import Spinner from '../components/atoms/Spinner' import Spinner from '../components/atoms/Spinner'
@ -19,7 +18,8 @@ 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'
const { title, description } = channels[0] // AI for Good channel
const { title, slug } = channels[0]
interface HomeProps { interface HomeProps {
history: History history: History
@ -121,7 +121,7 @@ export default class Home extends Component<HomeProps, HomeState> {
<Content wide> <Content wide>
<h2 className={styles.title}> <h2 className={styles.title}>
<Link to={`/channels/${slugify(title)}`}>{title}</Link> <Link to={`/channels/${slug}`}>{title}</Link>
</h2> </h2>
<div> <div>
{isLoadingCategory ? ( {isLoadingCategory ? (