mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
Merge pull request #15 from oceanprotocol/feature/states-flows
Feature/states flows
This commit is contained in:
commit
ce9a362b4a
@ -12,3 +12,16 @@
|
|||||||
.main {
|
.main {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loader {
|
||||||
|
text-align: center;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin-top: 25vh;
|
||||||
|
|
||||||
|
> div {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
33
src/App.tsx
33
src/App.tsx
@ -3,6 +3,7 @@ import Web3 from 'web3'
|
|||||||
import { BrowserRouter as Router } from 'react-router-dom'
|
import { BrowserRouter as Router } from 'react-router-dom'
|
||||||
import Header from './components/Header'
|
import Header from './components/Header'
|
||||||
import Footer from './components/Footer'
|
import Footer from './components/Footer'
|
||||||
|
import Spinner from './components/atoms/Spinner'
|
||||||
import { User } from './context/User'
|
import { User } from './context/User'
|
||||||
import { provideOcean } from './ocean'
|
import { provideOcean } from './ocean'
|
||||||
import Routes from './Routes'
|
import Routes from './Routes'
|
||||||
@ -21,6 +22,8 @@ declare global {
|
|||||||
interface AppState {
|
interface AppState {
|
||||||
isLogged: boolean
|
isLogged: boolean
|
||||||
isLoading: boolean
|
isLoading: boolean
|
||||||
|
isWeb3: boolean
|
||||||
|
account: string
|
||||||
web3: Web3
|
web3: Web3
|
||||||
ocean: {}
|
ocean: {}
|
||||||
startLogin: () => void
|
startLogin: () => void
|
||||||
@ -37,11 +40,13 @@ class App extends Component<{}, AppState> {
|
|||||||
public state = {
|
public state = {
|
||||||
isLogged: false,
|
isLogged: false,
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
|
isWeb3: false,
|
||||||
web3: new Web3(
|
web3: new Web3(
|
||||||
new Web3.providers.HttpProvider(
|
new Web3.providers.HttpProvider(
|
||||||
`${nodeScheme}://${nodeHost}:${nodePort}`
|
`${nodeScheme}://${nodeHost}:${nodePort}`
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
account: '',
|
||||||
ocean: {},
|
ocean: {},
|
||||||
startLogin: this.startLogin
|
startLogin: this.startLogin
|
||||||
}
|
}
|
||||||
@ -51,7 +56,6 @@ class App extends Component<{}, AppState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private startLoginProcess = async () => {
|
private startLoginProcess = async () => {
|
||||||
this.setState({ isLoading: true })
|
|
||||||
if (window.web3) {
|
if (window.web3) {
|
||||||
const web3 = new Web3(window.web3.currentProvider)
|
const web3 = new Web3(window.web3.currentProvider)
|
||||||
try {
|
try {
|
||||||
@ -59,15 +63,26 @@ class App extends Component<{}, AppState> {
|
|||||||
if (accounts.length > 0) {
|
if (accounts.length > 0) {
|
||||||
this.setState({
|
this.setState({
|
||||||
isLogged: true,
|
isLogged: true,
|
||||||
|
isWeb3: true,
|
||||||
|
account: accounts[0],
|
||||||
web3
|
web3
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (accounts.length === 0 && window.ethereum) {
|
if (accounts.length === 0 && window.ethereum) {
|
||||||
await window.ethereum.enable()
|
await window.ethereum.enable()
|
||||||
|
const newAccounts = await web3.eth.getAccounts()
|
||||||
|
if (newAccounts.length > 0) {
|
||||||
this.setState({
|
this.setState({
|
||||||
isLogged: true,
|
isLogged: true,
|
||||||
|
isWeb3: true,
|
||||||
|
account: newAccounts[0],
|
||||||
web3
|
web3
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
// failed to unlock
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// no unlock procedure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -76,17 +91,18 @@ class App extends Component<{}, AppState> {
|
|||||||
} else {
|
} else {
|
||||||
// no metamask/mist, show installation guide!
|
// no metamask/mist, show installation guide!
|
||||||
}
|
}
|
||||||
this.setState({ isLoading: false })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bootstrap = async () => {
|
private bootstrap = async () => {
|
||||||
if (window.web3) {
|
if (window.web3) {
|
||||||
|
this.setState({ isWeb3: true })
|
||||||
const web3 = new Web3(window.web3.currentProvider)
|
const web3 = new Web3(window.web3.currentProvider)
|
||||||
try {
|
try {
|
||||||
const accounts = await web3.eth.getAccounts()
|
const accounts = await web3.eth.getAccounts()
|
||||||
if (accounts.length > 0) {
|
if (accounts.length > 0) {
|
||||||
this.setState({
|
this.setState({
|
||||||
isLogged: true,
|
isLogged: true,
|
||||||
|
account: accounts[0],
|
||||||
web3
|
web3
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -94,11 +110,18 @@ class App extends Component<{}, AppState> {
|
|||||||
// continue with default
|
// continue with default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
const { ocean } = await provideOcean()
|
const { ocean } = await provideOcean()
|
||||||
this.setState({
|
this.setState({
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
ocean
|
ocean
|
||||||
})
|
})
|
||||||
|
} catch (e) {
|
||||||
|
// show loading error / unable to initialize ocean
|
||||||
|
this.setState({
|
||||||
|
isLoading: false
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
@ -110,7 +133,13 @@ class App extends Component<{}, AppState> {
|
|||||||
<Header />
|
<Header />
|
||||||
|
|
||||||
<main className={styles.main}>
|
<main className={styles.main}>
|
||||||
|
{this.state.isLoading ? (
|
||||||
|
<div className={styles.loader}>
|
||||||
|
<Spinner message="Connecting to Ocean..." />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
<Routes />
|
<Routes />
|
||||||
|
)}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<Footer />
|
<Footer />
|
||||||
|
@ -2,9 +2,13 @@
|
|||||||
|
|
||||||
.message {
|
.message {
|
||||||
margin-bottom: $spacer;
|
margin-bottom: $spacer;
|
||||||
color: $brand-grey-light;
|
color: $brand-grey;
|
||||||
padding-left: 1.5rem;
|
padding-left: 1.5rem;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
border-bottom: .1rem solid $brand-grey-lighter;
|
||||||
|
border-top: .1rem solid $brand-grey-lighter;
|
||||||
|
padding-top: $spacer / 2;
|
||||||
|
padding-bottom: $spacer / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// default: red square
|
// default: red square
|
||||||
@ -16,7 +20,7 @@
|
|||||||
margin-right: $spacer / 8;
|
margin-right: $spacer / 8;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
top: .3rem;
|
top: ($spacer / 2) + .3rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
// yellow triangle
|
// yellow triangle
|
||||||
@ -38,7 +42,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.account {
|
.account {
|
||||||
font-family: $font-family-monospace;
|
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-left: $spacer / 8;
|
margin-left: $spacer / 8;
|
||||||
|
background: none;
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,29 @@
|
|||||||
import React, { PureComponent } from 'react'
|
import React, { PureComponent } from 'react'
|
||||||
import Button from '../components/atoms/Button'
|
import Button from '../components/atoms/Button'
|
||||||
import styles from './Web3message.module.scss'
|
import styles from './Web3message.module.scss'
|
||||||
|
import { User } from '../context/User'
|
||||||
|
|
||||||
export default class Web3message extends PureComponent {
|
export default class Web3message extends PureComponent {
|
||||||
public render() {
|
public render() {
|
||||||
// let indicatorClasses = styles.indicatorCloseEnough
|
|
||||||
|
|
||||||
// if (this.props.activeAccount) {
|
|
||||||
// indicatorClasses = styles.indicatorActive
|
|
||||||
// }
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* IF no Web3 */}
|
<User.Consumer>
|
||||||
|
{states =>
|
||||||
|
!states.isWeb3
|
||||||
|
? this.noWeb3()
|
||||||
|
: !states.isLogged
|
||||||
|
? this.unlockAccount(states)
|
||||||
|
: states.isLogged
|
||||||
|
? this.haveAccount(states.account)
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
</User.Consumer>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
public noWeb3() {
|
||||||
|
return (
|
||||||
<div className={styles.message}>
|
<div className={styles.message}>
|
||||||
<span className={styles.indicator} /> No Web3 Browser. For
|
<span className={styles.indicator} /> No Web3 Browser. For
|
||||||
publishing an asset you need to use a Web3-capable plugin or
|
publishing an asset you need to use a Web3-capable plugin or
|
||||||
@ -22,27 +33,30 @@ export default class Web3message extends PureComponent {
|
|||||||
</a>
|
</a>
|
||||||
.
|
.
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{/* IF connected and account locked */}
|
public unlockAccount(states: any) {
|
||||||
|
return (
|
||||||
<div className={styles.message}>
|
<div className={styles.message}>
|
||||||
<span className={styles.indicatorCloseEnough} /> Account
|
<span className={styles.indicatorCloseEnough} /> Account locked.
|
||||||
locked. For publishing an asset you need to unlock your Web3
|
For publishing an asset you need to unlock your Web3 account.
|
||||||
account.
|
<Button link onClick={states.startLogin}>
|
||||||
<Button link>Unlock account</Button>
|
Unlock account
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{/* IF connected and unlocked */}
|
public haveAccount(account: string) {
|
||||||
|
return (
|
||||||
<div className={styles.message}>
|
<div className={styles.message}>
|
||||||
<span className={styles.indicatorActive} /> Connected with
|
<span className={styles.indicatorActive} /> Connected with
|
||||||
account
|
account
|
||||||
<span
|
<code className={styles.account} title={account && account}>
|
||||||
className={styles.account}
|
{`${account && account.substring(0, 20)}...`}
|
||||||
title="0xfehz2u89nfewhji432ntio43huof42huifewhnuefwo"
|
</code>
|
||||||
>
|
|
||||||
0xfehz2u89n...
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.spinnerMessage {
|
||||||
|
color: $brand-grey-light;
|
||||||
|
margin-top: $spacer / 2;
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes spinner {
|
@keyframes spinner {
|
||||||
to {
|
to {
|
||||||
transform: rotate(360deg);
|
transform: rotate(360deg);
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import styles from './Spinner.module.scss'
|
import styles from './Spinner.module.scss'
|
||||||
|
|
||||||
const Spinner = () => <div className={styles.spinner} />
|
const Spinner = ({ message }: { message?: string }) => (
|
||||||
|
<div className={styles.spinner}>
|
||||||
|
{message && <div className={styles.spinnerMessage}>{message}</div>}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
export default Spinner
|
export default Spinner
|
||||||
|
@ -3,6 +3,8 @@ import React from 'react'
|
|||||||
export const User = React.createContext({
|
export const User = React.createContext({
|
||||||
isLogged: false,
|
isLogged: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
isWeb3: false,
|
||||||
|
account: '',
|
||||||
web3: {},
|
web3: {},
|
||||||
ocean: {},
|
ocean: {},
|
||||||
startLogin: () => {
|
startLogin: () => {
|
||||||
|
@ -3,6 +3,7 @@ import React, { Component } from 'react'
|
|||||||
import Route from '../components/templates/Route'
|
import Route from '../components/templates/Route'
|
||||||
import Button from '../components/atoms/Button'
|
import Button from '../components/atoms/Button'
|
||||||
import { User } from '../context/User'
|
import { User } from '../context/User'
|
||||||
|
import quertString from 'query-string'
|
||||||
|
|
||||||
interface DetailsState {
|
interface DetailsState {
|
||||||
ddo: any
|
ddo: any
|
||||||
@ -26,6 +27,7 @@ export default class Details extends Component<DetailsProps, DetailsState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private purchaseAsset = async (ddo: any) => {
|
private purchaseAsset = async (ddo: any) => {
|
||||||
|
try {
|
||||||
const account = await this.context.ocean.getAccounts()
|
const account = await this.context.ocean.getAccounts()
|
||||||
const service = ddo.findServiceByType('Access')
|
const service = ddo.findServiceByType('Access')
|
||||||
const serviceAgreementSignatureResult: any = await this.context.ocean.signServiceAgreement(
|
const serviceAgreementSignatureResult: any = await this.context.ocean.signServiceAgreement(
|
||||||
@ -33,22 +35,25 @@ export default class Details extends Component<DetailsProps, DetailsState> {
|
|||||||
service.serviceDefinitionId,
|
service.serviceDefinitionId,
|
||||||
account[0]
|
account[0]
|
||||||
)
|
)
|
||||||
Logger.log(
|
|
||||||
'serviceAgreementSignatureResult',
|
|
||||||
serviceAgreementSignatureResult
|
|
||||||
)
|
|
||||||
|
|
||||||
await this.context.ocean.initializeServiceAgreement(
|
await this.context.ocean.initializeServiceAgreement(
|
||||||
ddo.id,
|
ddo.id,
|
||||||
service.serviceDefinitionId,
|
service.serviceDefinitionId,
|
||||||
serviceAgreementSignatureResult.serviceAgreementId,
|
serviceAgreementSignatureResult.serviceAgreementId,
|
||||||
serviceAgreementSignatureResult.serviceAgreementSignature,
|
serviceAgreementSignatureResult.serviceAgreementSignature,
|
||||||
(files: any) =>
|
(files: any) => {
|
||||||
Logger.log(
|
files.forEach((file: any) => {
|
||||||
`Got files, first files length in bytes: ${files[0].length}`
|
const parsedUrl: any = quertString.parseUrl(file)
|
||||||
),
|
setTimeout(() => {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
window.open(parsedUrl.query.url)
|
||||||
|
}, 100)
|
||||||
|
})
|
||||||
|
},
|
||||||
account[0]
|
account[0]
|
||||||
)
|
)
|
||||||
|
} catch (e) {
|
||||||
|
Logger.log('error', e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private showDetails = (ddo: any) => {
|
private showDetails = (ddo: any) => {
|
||||||
@ -56,7 +61,7 @@ export default class Details extends Component<DetailsProps, DetailsState> {
|
|||||||
<>
|
<>
|
||||||
<div>{JSON.stringify(this.state.metadata)}</div>
|
<div>{JSON.stringify(this.state.metadata)}</div>
|
||||||
|
|
||||||
<Button onClick={this.purchaseAsset(ddo)}>
|
<Button onClick={() => this.purchaseAsset(ddo)}>
|
||||||
Purchase asset
|
Purchase asset
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import React, { ChangeEvent, Component, FormEvent } from 'react'
|
import React, { ChangeEvent, Component, FormEvent } from 'react'
|
||||||
|
import { Logger } from '@oceanprotocol/squid'
|
||||||
import Route from '../components/templates/Route'
|
import Route from '../components/templates/Route'
|
||||||
import Button from '../components/atoms/Button'
|
import Button from '../components/atoms/Button'
|
||||||
import Form from '../components/atoms/Form/Form'
|
import Form from '../components/atoms/Form/Form'
|
||||||
@ -23,6 +24,10 @@ interface PublishState {
|
|||||||
copyrightHolder?: string
|
copyrightHolder?: string
|
||||||
categories?: string[]
|
categories?: string[]
|
||||||
tags?: string[]
|
tags?: string[]
|
||||||
|
isPublishing?: boolean
|
||||||
|
isPublished?: boolean
|
||||||
|
publishedDid?: string
|
||||||
|
publishingError?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
class Publish extends Component<{}, PublishState> {
|
class Publish extends Component<{}, PublishState> {
|
||||||
@ -36,7 +41,11 @@ class Publish extends Component<{}, PublishState> {
|
|||||||
type: 'dataset' as AssetType,
|
type: 'dataset' as AssetType,
|
||||||
license: '',
|
license: '',
|
||||||
copyrightHolder: '',
|
copyrightHolder: '',
|
||||||
categories: ['']
|
categories: [''],
|
||||||
|
isPublishing: false,
|
||||||
|
isPublished: false,
|
||||||
|
publishedDid: '',
|
||||||
|
publishingError: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
public formFields = (entries: any[]) =>
|
public formFields = (entries: any[]) =>
|
||||||
@ -80,8 +89,33 @@ class Publish extends Component<{}, PublishState> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private tryAgain = () => {
|
||||||
|
this.setState({ publishingError: '' })
|
||||||
|
}
|
||||||
|
|
||||||
|
private toStart = () => {
|
||||||
|
this.setState({
|
||||||
|
name: '',
|
||||||
|
dateCreated: new Date(),
|
||||||
|
description: '',
|
||||||
|
files: [''],
|
||||||
|
price: 0,
|
||||||
|
author: '',
|
||||||
|
type: 'dataset' as AssetType,
|
||||||
|
license: '',
|
||||||
|
copyrightHolder: '',
|
||||||
|
categories: [''],
|
||||||
|
isPublishing: false,
|
||||||
|
isPublished: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
private registerAsset = async (event: FormEvent<HTMLFormElement>) => {
|
private registerAsset = async (event: FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
this.setState({
|
||||||
|
publishingError: '',
|
||||||
|
isPublishing: true
|
||||||
|
})
|
||||||
const account = await this.context.ocean.getAccounts()
|
const account = await this.context.ocean.getAccounts()
|
||||||
const newAsset = {
|
const newAsset = {
|
||||||
// OEP-08 Attributes
|
// OEP-08 Attributes
|
||||||
@ -109,8 +143,26 @@ class Publish extends Component<{}, PublishState> {
|
|||||||
AssetModel.additionalInformation
|
AssetModel.additionalInformation
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
await this.context.ocean.registerAsset(newAsset, account[0])
|
const asset = await this.context.ocean.registerAsset(
|
||||||
|
newAsset,
|
||||||
|
account[0]
|
||||||
|
)
|
||||||
|
Logger.log('asset:', asset)
|
||||||
|
this.setState({
|
||||||
|
publishedDid: asset.id,
|
||||||
|
isPublished: true
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
// make readable errors
|
||||||
|
Logger.log('error:', e)
|
||||||
|
this.setState({
|
||||||
|
publishingError: e
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.setState({
|
||||||
|
isPublishing: false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
@ -120,6 +172,13 @@ class Publish extends Component<{}, PublishState> {
|
|||||||
<Route title="Publish">
|
<Route title="Publish">
|
||||||
<Web3message />
|
<Web3message />
|
||||||
|
|
||||||
|
{this.state.isPublishing ? (
|
||||||
|
this.publishingState()
|
||||||
|
) : this.state.publishingError ? (
|
||||||
|
this.errorState()
|
||||||
|
) : this.state.isPublished ? (
|
||||||
|
this.publishedState()
|
||||||
|
) : (
|
||||||
<Form
|
<Form
|
||||||
title={form.title}
|
title={form.title}
|
||||||
description={form.description}
|
description={form.description}
|
||||||
@ -130,20 +189,43 @@ class Publish extends Component<{}, PublishState> {
|
|||||||
<User.Consumer>
|
<User.Consumer>
|
||||||
{states =>
|
{states =>
|
||||||
states.isLogged ? (
|
states.isLogged ? (
|
||||||
<Button primary>
|
<Button primary>Register asset</Button>
|
||||||
Register asset (we are logged)
|
|
||||||
</Button>
|
|
||||||
) : (
|
) : (
|
||||||
<Button primary onClick={states.startLogin}>
|
<Button onClick={states.startLogin}>
|
||||||
Register asset (login first)
|
Register asset (login first)
|
||||||
</Button>
|
</Button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</User.Consumer>
|
</User.Consumer>
|
||||||
</Form>
|
</Form>
|
||||||
|
)}
|
||||||
</Route>
|
</Route>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public publishingState = () => {
|
||||||
|
return <div>Please sign with your crypto wallet</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
public errorState = () => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
Something went wrong,{' '}
|
||||||
|
<a onClick={() => this.tryAgain()}>try again</a>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
public publishedState = () => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
Your asset is published! See it{' '}
|
||||||
|
<a href={'/asset/' + this.state.publishedDid}>here</a>, submit
|
||||||
|
another asset by clicking{' '}
|
||||||
|
<a onClick={() => this.toStart()}>here</a>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Publish.contextType = User
|
Publish.contextType = User
|
||||||
|
@ -2,7 +2,7 @@ import queryString from 'query-string'
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import Route from '../components/templates/Route'
|
import Route from '../components/templates/Route'
|
||||||
import { provideOcean } from '../ocean'
|
import { User } from '../context/User'
|
||||||
|
|
||||||
interface SearchState {
|
interface SearchState {
|
||||||
results: any[]
|
results: any[]
|
||||||
@ -17,8 +17,6 @@ export default class Search extends Component<SearchProps, SearchState> {
|
|||||||
public state = { results: [] }
|
public state = { results: [] }
|
||||||
|
|
||||||
public async componentDidMount() {
|
public async componentDidMount() {
|
||||||
// temporary ocean init and asset retrieval
|
|
||||||
const { ocean } = await provideOcean()
|
|
||||||
const searchParams = queryString.parse(this.props.location.search)
|
const searchParams = queryString.parse(this.props.location.search)
|
||||||
const queryRequest: any = {
|
const queryRequest: any = {
|
||||||
offset: 100,
|
offset: 100,
|
||||||
@ -29,7 +27,7 @@ export default class Search extends Component<SearchProps, SearchState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const assets = await ocean.searchAssets(queryRequest)
|
const assets = await this.context.ocean.searchAssets(queryRequest)
|
||||||
this.setState({ results: assets })
|
this.setState({ results: assets })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,3 +54,5 @@ export default class Search extends Component<SearchProps, SearchState> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Search.contextType = User
|
||||||
|
Loading…
x
Reference in New Issue
Block a user