Skip to content

Commit b5409e6

Browse files
committed
feat: add online and offline theme
1 parent fbca211 commit b5409e6

File tree

9 files changed

+272
-444
lines changed

9 files changed

+272
-444
lines changed

src/App.js

+39-37
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ import PropTypes from 'prop-types';
33
import { connect } from 'react-redux';
44
import ReduxToastr from 'react-redux-toastr';
55
import { HashRouter as Router, Route, Switch } from 'react-router-dom';
6-
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
6+
import { MuiThemeProvider } from '@material-ui/core/styles';
77
import { withTranslation } from 'react-i18next';
8+
import { Detector } from 'react-detect-offline';
89
import Home from './Home';
910
import VisitSpace from './components/VisitSpace';
1011
import SpacesNearby from './components/SpacesNearby';
1112
import Settings from './components/Settings';
1213
import LoadSpace from './components/LoadSpace';
1314
import SpaceScreen from './components/space/SpaceScreen';
1415
import DeveloperScreen from './components/developer/DeveloperScreen';
16+
import { OnlineTheme, OfflineTheme } from './themes';
1517
import {
1618
SETTINGS_PATH,
1719
SPACE_PATH,
@@ -31,16 +33,6 @@ import {
3133
import { DEFAULT_LANGUAGE } from './config/constants';
3234
import './App.css';
3335

34-
const theme = createMuiTheme({
35-
typography: {
36-
useNextVariants: true,
37-
},
38-
palette: {
39-
primary: { light: '#5050d2', main: '#5050d2', dark: '#5050d2' },
40-
secondary: { light: '#eeeeee', main: '#eeeeee', dark: '#eeeeee' },
41-
},
42-
});
43-
4436
export class App extends Component {
4537
state = { height: 0 };
4638

@@ -107,29 +99,42 @@ export class App extends Component {
10799

108100
render() {
109101
const { height } = this.state;
102+
110103
return (
111-
<MuiThemeProvider theme={theme}>
112-
<div>
113-
<ReduxToastr
114-
transitionIn="fadeIn"
115-
preventDuplicates
116-
transitionOut="fadeOut"
117-
/>
118-
</div>
119-
<Router>
120-
<div className="app" style={{ height }}>
121-
<Switch>
122-
<Route exact path={HOME_PATH} component={Home} />
123-
<Route exact path={SPACES_NEARBY_PATH} component={SpacesNearby} />
124-
<Route exact path={VISIT_PATH} component={VisitSpace} />
125-
<Route exact path={LOAD_SPACE_PATH} component={LoadSpace} />
126-
<Route exact path={SETTINGS_PATH} component={Settings} />
127-
<Route exact path={SPACE_PATH} component={SpaceScreen} />
128-
<Route exact path={DEVELOPER_PATH} component={DeveloperScreen} />
129-
</Switch>
130-
</div>
131-
</Router>
132-
</MuiThemeProvider>
104+
<Detector
105+
render={({ online }) => (
106+
<MuiThemeProvider theme={online ? OnlineTheme : OfflineTheme}>
107+
<div>
108+
<ReduxToastr
109+
transitionIn="fadeIn"
110+
preventDuplicates
111+
transitionOut="fadeOut"
112+
/>
113+
</div>
114+
<Router>
115+
<div className="app" style={{ height }}>
116+
<Switch>
117+
<Route exact path={HOME_PATH} component={Home} />
118+
<Route
119+
exact
120+
path={SPACES_NEARBY_PATH}
121+
component={SpacesNearby}
122+
/>
123+
<Route exact path={VISIT_PATH} component={VisitSpace} />
124+
<Route exact path={LOAD_SPACE_PATH} component={LoadSpace} />
125+
<Route exact path={SETTINGS_PATH} component={Settings} />
126+
<Route exact path={SPACE_PATH} component={SpaceScreen} />
127+
<Route
128+
exact
129+
path={DEVELOPER_PATH}
130+
component={DeveloperScreen}
131+
/>
132+
</Switch>
133+
</div>
134+
</Router>
135+
</MuiThemeProvider>
136+
)}
137+
/>
133138
);
134139
}
135140
}
@@ -147,10 +152,7 @@ const mapDispatchToProps = {
147152
dispatchGetGeolocationEnabled: getGeolocationEnabled,
148153
};
149154

150-
const ConnectedApp = connect(
151-
mapStateToProps,
152-
mapDispatchToProps
153-
)(App);
155+
const ConnectedApp = connect(mapStateToProps, mapDispatchToProps)(App);
154156

155157
const TranslatedApp = withTranslation()(ConnectedApp);
156158

0 commit comments

Comments
 (0)