-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathroot.js
67 lines (62 loc) · 2.02 KB
/
root.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React, { lazy, Suspense } from 'react';
import { connect } from "react-redux";
import { hot } from 'react-hot-loader/root';
import Monitor from "./components/framework/monitor";
import KeyboardShortcuts from "./components/framework/keyboard-shortcuts";
import DatasetLoader from "./components/datasetLoader";
import Spinner from "./components/framework/spinner";
import Head from "./components/framework/head";
import Notifications from "./components/notifications/notifications";
const Main = lazy(() => import("./components/main"));
const Splash = lazy(() => import("./components/splash"));
const Status = lazy(() => import("./components/status"));
/** Hot Reload is happening but components are not getting rerendered.
* This triggers a window resize which in turn triggers a general
* rerender. A bit ham-fisted but gets the job done for the time being
* */
if (module.hot) {
setTimeout(() => window.dispatchEvent(new Event('resize')), 500);
}
@connect((state) => ({displayComponent: state.general.displayComponent}))
class MainComponentSwitch extends React.Component {
render() {
// console.log("MainComponentSwitch running (should be infrequent!)", this.props.displayComponent)
switch (this.props.displayComponent) {
case "main":
return (
<Suspense fallback={<Spinner/>}>
<Main/>
</Suspense>
);
case "splash":
return (
<Suspense fallback={null}>
<Splash/>
</Suspense>
);
case "status":
return (
<Suspense fallback={<Spinner/>}>
<Status/>
</Suspense>
);
case "datasetLoader":
return (<DatasetLoader/>);
default:
console.error(`reduxStore.general.displayComponent is invalid (${this.props.displayComponent})`);
return (<Splash/>);
}
}
}
const Root = () => {
return (
<div>
<Head/>
<Monitor/>
<KeyboardShortcuts/>
<Notifications/>
<MainComponentSwitch/>
</div>
);
};
export default hot(Root);