42 lines
1.6 KiB
JavaScript
42 lines
1.6 KiB
JavaScript
import React from 'react';
|
|
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
|
|
import AppContentContainer from './AppContentContainer';
|
|
import CIDetailViewContainer from './CIDetailViewContainer';
|
|
import reduxLang from '../../middleware/lang';
|
|
import StartScreenContainer from './../StartScreenContainer';
|
|
import { useSelector } from 'react-redux'
|
|
import { getLocaleFromURL, defineLocale, shouldDisplayDynamicComponent, getDjangoView, routePathForDynamicComponent } from '../../utils';
|
|
|
|
const App = ({ pending, menuOpen, setLocale, isPreLaunch }) => {
|
|
// set initial language
|
|
setLocale(defineLocale(isPreLaunch));
|
|
let localeFromURL = getLocaleFromURL(window.location.pathname);
|
|
if (localeFromURL === undefined) {
|
|
localeFromURL = ''
|
|
}
|
|
const basename = '/' + localeFromURL + useSelector(state => state.urls.site);
|
|
|
|
const activeSite = useSelector(state => state.urls.site);
|
|
const urls = useSelector(state => state.urls.allSites[activeSite].urls);
|
|
const DynamicComponent = React.memo(() => (
|
|
<div className="AppContent">
|
|
<div dangerouslySetInnerHTML={{ __html: getDjangoView() }} />
|
|
</div>
|
|
));
|
|
return (
|
|
<div
|
|
className={`App touch ${pending ? 'loading' : ''}`}
|
|
>
|
|
<Router basename={basename}>
|
|
<Switch>
|
|
{ shouldDisplayDynamicComponent(urls) ? <Route path={routePathForDynamicComponent(basename)} component={DynamicComponent} /> : null }
|
|
<Route path='/' component={AppContentContainer} />
|
|
</Switch>
|
|
<Route path='/catalog/:itemId' component={CIDetailViewContainer} />
|
|
<Route path='/start' component={StartScreenContainer} />
|
|
</Router>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default reduxLang()(App);
|