2018-07-31 17:26:04 +00:00
|
|
|
import SetCSSColour from 'Components/utils/SetCssColour'
|
2018-09-20 12:44:24 +00:00
|
|
|
import { TrackerProvider } from 'Components/utils/withTracker'
|
2018-06-21 09:52:00 +00:00
|
|
|
import createHistory from 'history/createBrowserHistory'
|
|
|
|
import i18next from 'i18next'
|
2018-07-12 08:09:41 +00:00
|
|
|
import React, { PureComponent } from 'react'
|
2018-06-21 09:52:00 +00:00
|
|
|
import { I18nextProvider } from 'react-i18next'
|
2018-05-24 16:28:37 +00:00
|
|
|
import { Provider } from 'react-redux'
|
2018-06-21 09:52:00 +00:00
|
|
|
import { Router } from 'react-router-dom'
|
2018-07-12 08:09:41 +00:00
|
|
|
import reducers from 'Reducers/rootReducer'
|
2018-05-24 16:28:37 +00:00
|
|
|
import { applyMiddleware, compose, createStore } from 'redux'
|
2018-07-23 13:21:00 +00:00
|
|
|
import thunk from 'redux-thunk'
|
2018-07-12 08:09:41 +00:00
|
|
|
import computeThemeColours from 'Ui/themeColours'
|
2018-08-29 15:23:29 +00:00
|
|
|
import { getIframeOption, inIframe } from './utils'
|
2018-05-24 16:28:37 +00:00
|
|
|
|
|
|
|
let initialStore = {
|
2018-08-28 13:59:41 +00:00
|
|
|
themeColours: computeThemeColours(getIframeOption('couleur'))
|
2018-05-24 16:28:37 +00:00
|
|
|
}
|
|
|
|
|
2018-05-25 09:46:46 +00:00
|
|
|
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
|
2018-05-24 16:28:37 +00:00
|
|
|
|
2018-08-23 14:42:47 +00:00
|
|
|
if (
|
|
|
|
process.env.NODE_ENV === 'production' &&
|
|
|
|
'serviceWorker' in navigator &&
|
|
|
|
!inIframe()
|
|
|
|
) {
|
2018-07-04 17:45:43 +00:00
|
|
|
window.addEventListener('load', () => {
|
|
|
|
navigator.serviceWorker
|
2018-07-05 09:54:41 +00:00
|
|
|
.register('/sw.js')
|
2018-07-04 17:45:43 +00:00
|
|
|
.then(registration => {
|
|
|
|
console.log('SW registered: ', registration)
|
|
|
|
})
|
|
|
|
.catch(registrationError => {
|
|
|
|
console.log('SW registration failed: ', registrationError)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2018-07-12 08:09:41 +00:00
|
|
|
|
|
|
|
export default class Layout extends PureComponent {
|
2018-07-23 13:21:00 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.history = createHistory({
|
2018-07-12 08:09:41 +00:00
|
|
|
basename: process.env.NODE_ENV === 'production' ? '' : this.props.basename
|
|
|
|
})
|
2018-07-23 13:21:00 +00:00
|
|
|
const storeEnhancer = composeEnhancers(
|
|
|
|
applyMiddleware(
|
|
|
|
// Allows us to painlessly do route transition in action creators
|
|
|
|
thunk.withExtraArgument(this.history),
|
2018-09-20 12:44:24 +00:00
|
|
|
...props.reduxMiddlewares
|
2018-07-23 13:21:00 +00:00
|
|
|
)
|
|
|
|
)
|
2018-08-28 13:59:41 +00:00
|
|
|
this.store = createStore(
|
|
|
|
reducers,
|
|
|
|
{ ...initialStore, ...this.props.initialStore },
|
|
|
|
storeEnhancer
|
|
|
|
)
|
|
|
|
this.props.onStoreCreated(this.store)
|
2018-07-31 13:32:41 +00:00
|
|
|
if (this.props.language) {
|
|
|
|
i18next.changeLanguage(this.props.language)
|
|
|
|
}
|
2018-07-12 08:09:41 +00:00
|
|
|
}
|
|
|
|
render() {
|
|
|
|
return (
|
2018-09-05 14:18:39 +00:00
|
|
|
// If IE < 11 display nothing
|
2018-07-23 13:21:00 +00:00
|
|
|
<Provider store={this.store}>
|
2018-09-20 12:44:24 +00:00
|
|
|
<TrackerProvider value={this.props.tracker}>
|
2018-07-31 17:26:04 +00:00
|
|
|
<SetCSSColour />
|
2018-07-12 08:09:41 +00:00
|
|
|
<I18nextProvider i18n={i18next}>
|
2018-09-20 12:44:24 +00:00
|
|
|
<Router history={this.props.tracker.connectToHistory(this.history)}>
|
2018-07-12 08:09:41 +00:00
|
|
|
<>{this.props.children}</>
|
|
|
|
</Router>
|
|
|
|
</I18nextProvider>
|
|
|
|
</TrackerProvider>
|
|
|
|
</Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|