Skip to content

Commit b2dd03d

Browse files
Merge pull request #233 from graasp/225/colorTheme
feat: add online and offline theme
2 parents fb75136 + c0b2417 commit b2dd03d

File tree

13 files changed

+320
-446
lines changed

13 files changed

+320
-446
lines changed

public/app/config/messages.js

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const ERROR_CLEARING_USER_INPUT_MESSAGE =
4747
'There was an error clearing the user input.';
4848
const SUCCESS_CLEARING_USER_INPUT_MESSAGE =
4949
'User input was successfully cleared.';
50+
const CONNECTION_MESSAGE_HEADER = 'Connection Status';
51+
const CONNECTION_OFFLINE_MESSAGE = 'You are offline.';
52+
const CONNECTION_ONLINE_MESSAGE = 'You are online.';
5053

5154
module.exports = {
5255
ERROR_GETTING_DEVELOPER_MODE,
@@ -83,4 +86,7 @@ module.exports = {
8386
ERROR_SYNCING_MESSAGE,
8487
ERROR_CLEARING_USER_INPUT_MESSAGE,
8588
SUCCESS_CLEARING_USER_INPUT_MESSAGE,
89+
CONNECTION_MESSAGE_HEADER,
90+
CONNECTION_OFFLINE_MESSAGE,
91+
CONNECTION_ONLINE_MESSAGE,
8692
};

src/App.js

+71-37
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import { connect } from 'react-redux';
4-
import ReduxToastr from 'react-redux-toastr';
4+
import ReduxToastr, { toastr } 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';
7+
import { withStyles } from '@material-ui/core';
78
import { withTranslation } from 'react-i18next';
9+
import { Detector } from 'react-detect-offline';
10+
import WifiIcon from '@material-ui/icons/Wifi';
11+
import WifiOffIcon from '@material-ui/icons/WifiOff';
812
import Home from './Home';
913
import VisitSpace from './components/VisitSpace';
1014
import SpacesNearby from './components/SpacesNearby';
1115
import Settings from './components/Settings';
1216
import LoadSpace from './components/LoadSpace';
1317
import SpaceScreen from './components/space/SpaceScreen';
1418
import DeveloperScreen from './components/developer/DeveloperScreen';
19+
import { OnlineTheme, OfflineTheme } from './themes';
1520
import {
1621
SETTINGS_PATH,
1722
SPACE_PATH,
@@ -29,16 +34,15 @@ import {
2934
getGeolocationEnabled,
3035
} from './actions/user';
3136
import { DEFAULT_LANGUAGE } from './config/constants';
37+
import {
38+
CONNECTION_MESSAGE_HEADER,
39+
CONNECTION_OFFLINE_MESSAGE,
40+
CONNECTION_ONLINE_MESSAGE,
41+
} from './config/messages';
3242
import './App.css';
3343

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-
},
44+
const styles = () => ({
45+
toastrIcon: { marginBottom: '-20px', fontSize: '45px' },
4246
});
4347

4448
export class App extends Component {
@@ -55,6 +59,9 @@ export class App extends Component {
5559
changeLanguage: PropTypes.func.isRequired,
5660
}).isRequired,
5761
geolocationEnabled: PropTypes.bool.isRequired,
62+
classes: PropTypes.shape({
63+
toastrIcon: PropTypes.string.isRequired,
64+
}).isRequired,
5865
};
5966

6067
static defaultProps = {
@@ -105,31 +112,59 @@ export class App extends Component {
105112
this.setState({ height: window.innerHeight });
106113
};
107114

115+
triggerConnectionToastr = online => {
116+
const { classes } = this.props;
117+
118+
if (online) {
119+
toastr.light(CONNECTION_MESSAGE_HEADER, CONNECTION_ONLINE_MESSAGE, {
120+
icon: <WifiIcon className={classes.toastrIcon} />,
121+
});
122+
} else {
123+
toastr.light(CONNECTION_MESSAGE_HEADER, CONNECTION_OFFLINE_MESSAGE, {
124+
icon: <WifiOffIcon className={classes.toastrIcon} />,
125+
});
126+
}
127+
};
128+
108129
render() {
109130
const { height } = this.state;
131+
110132
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>
133+
<Detector
134+
render={({ online }) => (
135+
<MuiThemeProvider theme={online ? OnlineTheme : OfflineTheme}>
136+
{this.triggerConnectionToastr(online)}
137+
<div>
138+
<ReduxToastr
139+
transitionIn="fadeIn"
140+
preventDuplicates
141+
transitionOut="fadeOut"
142+
/>
143+
</div>
144+
<Router>
145+
<div className="app" style={{ height }}>
146+
<Switch>
147+
<Route exact path={HOME_PATH} component={Home} />
148+
<Route
149+
exact
150+
path={SPACES_NEARBY_PATH}
151+
component={SpacesNearby}
152+
/>
153+
<Route exact path={VISIT_PATH} component={VisitSpace} />
154+
<Route exact path={LOAD_SPACE_PATH} component={LoadSpace} />
155+
<Route exact path={SETTINGS_PATH} component={Settings} />
156+
<Route exact path={SPACE_PATH} component={SpaceScreen} />
157+
<Route
158+
exact
159+
path={DEVELOPER_PATH}
160+
component={DeveloperScreen}
161+
/>
162+
</Switch>
163+
</div>
164+
</Router>
165+
</MuiThemeProvider>
166+
)}
167+
/>
133168
);
134169
}
135170
}
@@ -147,11 +182,10 @@ const mapDispatchToProps = {
147182
dispatchGetGeolocationEnabled: getGeolocationEnabled,
148183
};
149184

150-
const ConnectedApp = connect(
151-
mapStateToProps,
152-
mapDispatchToProps
153-
)(App);
185+
const ConnectedApp = connect(mapStateToProps, mapDispatchToProps)(App);
186+
187+
const StyledApp = withStyles(styles, { withTheme: true })(ConnectedApp);
154188

155-
const TranslatedApp = withTranslation()(ConnectedApp);
189+
const TranslatedApp = withTranslation()(StyledApp);
156190

157191
export default TranslatedApp;

0 commit comments

Comments
 (0)