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

error state for missing asset

This commit is contained in:
Matthias Kretschmann 2019-05-27 19:16:56 +02:00
parent be6c478ca7
commit f8cb601eb7
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 26 additions and 6 deletions

View File

@ -0,0 +1,12 @@
@import '../../../styles/variables';
.error {
text-align: center;
margin: 20vh auto 0 auto;
background: $red;
border-radius: $border-radius;
padding: $spacer / 2;
width: fit-content;
color: $brand-white;
font-weight: $font-weight-bold;
}

View File

@ -7,8 +7,9 @@ import AssetDetails from './AssetDetails'
import stylesApp from '../../../App.module.scss' import stylesApp from '../../../App.module.scss'
import Content from '../../atoms/Content' import Content from '../../atoms/Content'
import CategoryImage from '../../atoms/CategoryImage' import CategoryImage from '../../atoms/CategoryImage'
import styles from './index.module.scss'
interface DetailsProps { interface AssetProps {
location: Location location: Location
match: { match: {
params: { params: {
@ -17,15 +18,17 @@ interface DetailsProps {
} }
} }
interface DetailsState { interface AssetState {
ddo: DDO ddo: DDO
metadata: MetaData metadata: MetaData
error: string
} }
export default class Details extends Component<DetailsProps, DetailsState> { export default class Asset extends Component<AssetProps, AssetState> {
public state = { public state = {
ddo: ({} as any) as DDO, ddo: ({} as any) as DDO,
metadata: ({ base: { name: '' } } as any) as MetaData metadata: ({ base: { name: '' } } as any) as MetaData,
error: ''
} }
public async componentDidMount() { public async componentDidMount() {
@ -40,11 +43,14 @@ export default class Details extends Component<DetailsProps, DetailsState> {
this.setState({ ddo, metadata }) this.setState({ ddo, metadata })
} catch (error) { } catch (error) {
Logger.error(error.message) Logger.error(error.message)
this.setState({
error: `We encountered an error: ${error.message}.`
})
} }
} }
public render() { public render() {
const { metadata, ddo } = this.state const { metadata, ddo, error } = this.state
return metadata.base.name !== '' ? ( return metadata.base.name !== '' ? (
<Route <Route
@ -63,6 +69,8 @@ export default class Details extends Component<DetailsProps, DetailsState> {
<AssetDetails metadata={metadata} ddo={ddo} /> <AssetDetails metadata={metadata} ddo={ddo} />
</Content> </Content>
</Route> </Route>
) : error !== '' ? (
<div className={styles.error}>{error}</div>
) : ( ) : (
<div className={stylesApp.loader}> <div className={stylesApp.loader}>
<Spinner message={'Loading asset...'} /> <Spinner message={'Loading asset...'} />
@ -71,4 +79,4 @@ export default class Details extends Component<DetailsProps, DetailsState> {
} }
} }
Details.contextType = User Asset.contextType = User