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
6
import { MuiThemeProvider } from '@material-ui/core/styles' ;
7
+ import { withStyles } from '@material-ui/core' ;
7
8
import { withTranslation } from 'react-i18next' ;
8
9
import { Detector } from 'react-detect-offline' ;
10
+ import WifiIcon from '@material-ui/icons/Wifi' ;
11
+ import WifiOffIcon from '@material-ui/icons/WifiOff' ;
9
12
import Home from './Home' ;
10
13
import VisitSpace from './components/VisitSpace' ;
11
14
import SpacesNearby from './components/SpacesNearby' ;
@@ -31,8 +34,17 @@ import {
31
34
getGeolocationEnabled ,
32
35
} from './actions/user' ;
33
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' ;
34
42
import './App.css' ;
35
43
44
+ const styles = ( ) => ( {
45
+ toastrIcon : { marginBottom : '-20px' , fontSize : '45px' } ,
46
+ } ) ;
47
+
36
48
export class App extends Component {
37
49
state = { height : 0 } ;
38
50
@@ -47,6 +59,9 @@ export class App extends Component {
47
59
changeLanguage : PropTypes . func . isRequired ,
48
60
} ) . isRequired ,
49
61
geolocationEnabled : PropTypes . bool . isRequired ,
62
+ classes : PropTypes . shape ( {
63
+ toastrIcon : PropTypes . string . isRequired ,
64
+ } ) . isRequired ,
50
65
} ;
51
66
52
67
static defaultProps = {
@@ -97,13 +112,28 @@ export class App extends Component {
97
112
this . setState ( { height : window . innerHeight } ) ;
98
113
} ;
99
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
+
100
129
render ( ) {
101
130
const { height } = this . state ;
102
131
103
132
return (
104
133
< Detector
105
134
render = { ( { online } ) => (
106
135
< MuiThemeProvider theme = { online ? OnlineTheme : OfflineTheme } >
136
+ { this . triggerConnectionToastr ( online ) }
107
137
< div >
108
138
< ReduxToastr
109
139
transitionIn = "fadeIn"
@@ -154,6 +184,8 @@ const mapDispatchToProps = {
154
184
155
185
const ConnectedApp = connect ( mapStateToProps , mapDispatchToProps ) ( App ) ;
156
186
157
- const TranslatedApp = withTranslation ( ) ( ConnectedApp ) ;
187
+ const StyledApp = withStyles ( styles , { withTheme : true } ) ( ConnectedApp ) ;
188
+
189
+ const TranslatedApp = withTranslation ( ) ( StyledApp ) ;
158
190
159
191
export default TranslatedApp ;
0 commit comments