1
1
import React , { Component } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { connect } from 'react-redux' ;
4
- import ReduxToastr from 'react-redux-toastr' ;
4
+ import ReduxToastr , { toastr } from 'react-redux-toastr' ;
5
5
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' ;
7
8
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' ;
8
12
import Home from './Home' ;
9
13
import VisitSpace from './components/VisitSpace' ;
10
14
import SpacesNearby from './components/SpacesNearby' ;
11
15
import Settings from './components/Settings' ;
12
16
import LoadSpace from './components/LoadSpace' ;
13
17
import SpaceScreen from './components/space/SpaceScreen' ;
14
18
import DeveloperScreen from './components/developer/DeveloperScreen' ;
19
+ import { OnlineTheme , OfflineTheme } from './themes' ;
15
20
import {
16
21
SETTINGS_PATH ,
17
22
SPACE_PATH ,
@@ -29,16 +34,15 @@ import {
29
34
getGeolocationEnabled ,
30
35
} from './actions/user' ;
31
36
import { DEFAULT_LANGUAGE } from './config/constants' ;
37
+ import {
38
+ CONNECTION_MESSAGE_HEADER ,
39
+ CONNECTION_OFFLINE_MESSAGE ,
40
+ CONNECTION_ONLINE_MESSAGE ,
41
+ } from './config/messages' ;
32
42
import './App.css' ;
33
43
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' } ,
42
46
} ) ;
43
47
44
48
export class App extends Component {
@@ -55,6 +59,9 @@ export class App extends Component {
55
59
changeLanguage : PropTypes . func . isRequired ,
56
60
} ) . isRequired ,
57
61
geolocationEnabled : PropTypes . bool . isRequired ,
62
+ classes : PropTypes . shape ( {
63
+ toastrIcon : PropTypes . string . isRequired ,
64
+ } ) . isRequired ,
58
65
} ;
59
66
60
67
static defaultProps = {
@@ -105,31 +112,59 @@ export class App extends Component {
105
112
this . setState ( { height : window . innerHeight } ) ;
106
113
} ;
107
114
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
+
108
129
render ( ) {
109
130
const { height } = this . state ;
131
+
110
132
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
+ />
133
168
) ;
134
169
}
135
170
}
@@ -147,11 +182,10 @@ const mapDispatchToProps = {
147
182
dispatchGetGeolocationEnabled : getGeolocationEnabled ,
148
183
} ;
149
184
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 ) ;
154
188
155
- const TranslatedApp = withTranslation ( ) ( ConnectedApp ) ;
189
+ const TranslatedApp = withTranslation ( ) ( StyledApp ) ;
156
190
157
191
export default TranslatedApp ;
0 commit comments