1
1
import React , { Component } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { connect } from 'react-redux' ;
4
- import ReduxToastr , { toastr } from 'react-redux-toastr' ;
4
+ import { toastr } from 'react-redux-toastr' ;
5
5
import { HashRouter as Router , Route , Switch } from 'react-router-dom' ;
6
- import { MuiThemeProvider } from '@material-ui/core/styles' ;
7
6
import { withStyles } from '@material-ui/core' ;
8
7
import { withTranslation } from 'react-i18next' ;
9
- import { Detector } from 'react-detect-offline' ;
10
8
import WifiIcon from '@material-ui/icons/Wifi' ;
11
9
import WifiOffIcon from '@material-ui/icons/WifiOff' ;
12
10
import Home from './Home' ;
@@ -19,7 +17,6 @@ import SyncScreen from './components/space/SyncScreen';
19
17
import ExportSelectionScreen from './components/space/export/ExportSelectionScreen' ;
20
18
import LoadSelectionScreen from './components/space/load/LoadSelectionScreen' ;
21
19
import DeveloperScreen from './components/developer/DeveloperScreen' ;
22
- import { OnlineTheme , OfflineTheme } from './themes' ;
23
20
import Dashboard from './components/dashboard/Dashboard' ;
24
21
import SignInScreen from './components/signin/SignInScreen' ;
25
22
import Authorization from './components/Authorization' ;
@@ -83,6 +80,7 @@ export class App extends Component {
83
80
classes : PropTypes . shape ( {
84
81
toastrIcon : PropTypes . string . isRequired ,
85
82
} ) . isRequired ,
83
+ connexionStatus : PropTypes . bool . isRequired ,
86
84
} ;
87
85
88
86
static defaultProps = {
@@ -115,8 +113,9 @@ export class App extends Component {
115
113
lang : prevLang ,
116
114
geolocationEnabled : prevGeolocationEnabled ,
117
115
dispatchGetGeolocation,
116
+ connexionStatus : prevConnexionStatus ,
118
117
} ) {
119
- const { lang, i18n, geolocationEnabled } = this . props ;
118
+ const { lang, i18n, geolocationEnabled, connexionStatus } = this . props ;
120
119
if ( lang !== prevLang ) {
121
120
i18n . changeLanguage ( lang ) ;
122
121
}
@@ -125,6 +124,11 @@ export class App extends Component {
125
124
if ( geolocationEnabled && geolocationEnabled !== prevGeolocationEnabled ) {
126
125
dispatchGetGeolocation ( ) ;
127
126
}
127
+
128
+ // display toastr when connexion status changes
129
+ if ( connexionStatus !== prevConnexionStatus ) {
130
+ this . triggerConnectionToastr ( ) ;
131
+ }
128
132
}
129
133
130
134
componentWillUnmount ( ) {
@@ -135,10 +139,10 @@ export class App extends Component {
135
139
this . setState ( { height : window . innerHeight } ) ;
136
140
} ;
137
141
138
- triggerConnectionToastr = online => {
139
- const { classes } = this . props ;
142
+ triggerConnectionToastr = ( ) => {
143
+ const { classes, connexionStatus } = this . props ;
140
144
141
- if ( online ) {
145
+ if ( connexionStatus ) {
142
146
toastr . light ( CONNECTION_MESSAGE_HEADER , CONNECTION_ONLINE_MESSAGE , {
143
147
icon : < WifiIcon className = { classes . toastrIcon } /> ,
144
148
} ) ;
@@ -153,106 +157,84 @@ export class App extends Component {
153
157
const { height } = this . state ;
154
158
155
159
return (
156
- < Detector
157
- render = { ( { online } ) => (
158
- < MuiThemeProvider theme = { online ? OnlineTheme : OfflineTheme } >
159
- { this . triggerConnectionToastr ( online ) }
160
- < div >
161
- < ReduxToastr
162
- transitionIn = "fadeIn"
163
- preventDuplicates
164
- transitionOut = "fadeOut"
165
- />
166
- </ div >
167
- < Router >
168
- < div className = "app" style = { { height } } >
169
- < Switch >
170
- < Route exact path = { SIGN_IN_PATH } component = { SignInScreen } />
171
- < Route
172
- exact
173
- path = { HOME_PATH }
174
- component = { Authorization ( ) ( Home ) }
175
- />
176
- < Route
177
- exact
178
- path = { SAVED_SPACES_PATH }
179
- component = { Authorization ( ) ( SavedSpaces ) }
180
- />
181
- < Route
182
- exact
183
- path = { SPACES_NEARBY_PATH }
184
- component = { Authorization ( ) ( SpacesNearby ) }
185
- />
186
- < Route
187
- exact
188
- path = { VISIT_PATH }
189
- component = { Authorization ( ) ( VisitSpace ) }
190
- />
191
- < Route
192
- exact
193
- path = { LOAD_SPACE_PATH }
194
- component = { Authorization ( ) ( LoadSpace ) }
195
- />
196
- < Route
197
- exact
198
- path = { LOAD_SELECTION_SPACE_PATH }
199
- component = { Authorization ( ) ( LoadSelectionScreen ) }
200
- />
201
- < Route
202
- exact
203
- path = { SETTINGS_PATH }
204
- component = { Authorization ( ) ( Settings ) }
205
- />
206
- < Route
207
- exact
208
- path = { SYNC_SPACE_PATH }
209
- component = { Authorization ( ) ( SyncScreen ) }
210
- />
211
- < Route
212
- exact
213
- path = { buildExportSelectionPathForSpaceId ( ) }
214
- component = { Authorization ( ) ( ExportSelectionScreen ) }
215
- />
216
- < Route
217
- exact
218
- path = { SPACE_PATH }
219
- component = { Authorization ( ) ( SpaceScreen ) }
220
- />
221
- < Route
222
- exact
223
- path = { DASHBOARD_PATH }
224
- component = { Authorization ( ) ( Dashboard ) }
225
- />
226
- < Route
227
- exact
228
- path = { buildClassroomPath ( ) }
229
- component = { Authorization ( [ USER_MODES . TEACHER ] ) (
230
- ClassroomScreen
231
- ) }
232
- />
233
- < Route
234
- exact
235
- path = { CLASSROOMS_PATH }
236
- component = { Authorization ( [ USER_MODES . TEACHER ] ) ( Classrooms ) }
237
- />
238
- < Route
239
- exact
240
- path = { buildImportDataInClassroomPath ( ) }
241
- component = { Authorization ( [ USER_MODES . TEACHER ] ) (
242
- ImportDataScreen
243
- ) }
244
- />
245
- < Route
246
- exact
247
- path = { DEVELOPER_PATH }
248
- component = { Authorization ( ) ( DeveloperScreen ) }
249
- />
250
- </ Switch >
251
- </ div >
252
- </ Router >
253
- </ MuiThemeProvider >
254
- ) }
255
- />
160
+ < Router >
161
+ < div className = "app" style = { { height } } >
162
+ < Switch >
163
+ < Route exact path = { SIGN_IN_PATH } component = { SignInScreen } />
164
+ < Route exact path = { HOME_PATH } component = { Authorization ( ) ( Home ) } />
165
+ < Route
166
+ exact
167
+ path = { SAVED_SPACES_PATH }
168
+ component = { Authorization ( ) ( SavedSpaces ) }
169
+ />
170
+ < Route
171
+ exact
172
+ path = { SPACES_NEARBY_PATH }
173
+ component = { Authorization ( ) ( SpacesNearby ) }
174
+ />
175
+ < Route
176
+ exact
177
+ path = { VISIT_PATH }
178
+ component = { Authorization ( ) ( VisitSpace ) }
179
+ />
180
+ < Route
181
+ exact
182
+ path = { LOAD_SPACE_PATH }
183
+ component = { Authorization ( ) ( LoadSpace ) }
184
+ />
185
+ < Route
186
+ exact
187
+ path = { LOAD_SELECTION_SPACE_PATH }
188
+ component = { Authorization ( ) ( LoadSelectionScreen ) }
189
+ />
190
+ < Route
191
+ exact
192
+ path = { SETTINGS_PATH }
193
+ component = { Authorization ( ) ( Settings ) }
194
+ />
195
+ < Route
196
+ exact
197
+ path = { SYNC_SPACE_PATH }
198
+ component = { Authorization ( ) ( SyncScreen ) }
199
+ />
200
+ < Route
201
+ exact
202
+ path = { buildExportSelectionPathForSpaceId ( ) }
203
+ component = { Authorization ( ) ( ExportSelectionScreen ) }
204
+ />
205
+ < Route
206
+ exact
207
+ path = { SPACE_PATH }
208
+ component = { Authorization ( ) ( SpaceScreen ) }
209
+ />
210
+ < Route
211
+ exact
212
+ path = { DASHBOARD_PATH }
213
+ component = { Authorization ( ) ( Dashboard ) }
214
+ />
215
+ < Route
216
+ exact
217
+ path = { buildClassroomPath ( ) }
218
+ component = { Authorization ( [ USER_MODES . TEACHER ] ) ( ClassroomScreen ) }
219
+ />
220
+ < Route
221
+ exact
222
+ path = { CLASSROOMS_PATH }
223
+ component = { Authorization ( [ USER_MODES . TEACHER ] ) ( Classrooms ) }
224
+ />
225
+ < Route
226
+ exact
227
+ path = { buildImportDataInClassroomPath ( ) }
228
+ component = { Authorization ( [ USER_MODES . TEACHER ] ) ( ImportDataScreen ) }
229
+ />
230
+ < Route
231
+ exact
232
+ path = { DEVELOPER_PATH }
233
+ component = { Authorization ( ) ( DeveloperScreen ) }
234
+ />
235
+ </ Switch >
236
+ </ div >
237
+ </ Router >
256
238
) ;
257
239
}
258
240
}
0 commit comments