-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathindex.js
53 lines (49 loc) · 1.82 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React from "react";
import { connect } from "react-redux";
import DefaultSplashContent from "./splash";
import { hasExtension, getExtension } from "../../util/extensions";
import ErrorBoundary from "../../util/errorBoundry";
import { fetchJSON } from "../../util/serverInteraction";
import { getServerAddress, controlsHiddenWidth } from "../../util/globals";
import { changePage } from "../../actions/navigation";
const SplashContent = hasExtension("splashComponent") ?
getExtension("splashComponent") :
DefaultSplashContent;
/* TODO: check that when compiling DefaultSplashContent isn't included if extension is defined */
@connect((state) => ({
errorMessage: state.general.errorMessage,
browserDimensions: state.browserDimensions.browserDimensions,
reduxPathname: state.general.pathname
}))
class Splash extends React.Component {
constructor(props) {
super(props);
/* state is set via the returned JSON from the server (aka charon) in the fetch in CDM */
this.state = {available: {}, errorMessage: undefined};
}
componentDidMount() {
fetchJSON(`${getServerAddress()}/getAvailable?prefix=${this.props.reduxPathname}`)
.then((json) => {
this.setState({available: json});
})
.catch((err) => {
this.setState({errorMessage: "Error in getting available datasets"});
console.warn(err.message);
});
}
render() {
return (
<ErrorBoundary>
<SplashContent
isMobile={this.props.browserDimensions.width < controlsHiddenWidth}
available={this.state.available}
browserDimensions={this.props.browserDimensions}
dispatch={this.props.dispatch}
errorMessage={this.props.errorMessage || this.state.errorMessage}
changePage={changePage}
/>
</ErrorBoundary>
);
}
}
export default Splash;