This commit is contained in:
cyril lopez 2018-10-30 17:27:43 +01:00
parent 20ee8f9e1e
commit b06997014a
5 changed files with 57 additions and 13 deletions

File diff suppressed because one or more lines are too long

View File

@ -14,14 +14,12 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Switch, Route } from 'react-router-dom';
import AdminPage from 'containers/AdminPage';
import NotFoundPage from 'containers/NotFoundPage';
import NotificationProvider from 'containers/NotificationProvider';
import AppLoader from 'containers/AppLoader';
import LoadingIndicatorPage from 'components/LoadingIndicatorPage';
import '../../styles/main.scss';
import styles from './styles.scss';
export class App extends React.Component { // eslint-disable-line react/prefer-stateless-function
@ -29,12 +27,22 @@ export class App extends React.Component { // eslint-disable-line react/prefer-s
return (
<div>
<NotificationProvider />
<div className={styles.container}>
<Switch>
<Route path="/" component={AdminPage} />
<Route path="" component={NotFoundPage} />
</Switch>
</div>
<AppLoader>
{({ shouldLoad }) => {
if (shouldLoad) {
return <LoadingIndicatorPage />;
}
return (
<div className={styles.container}>
<Switch>
<Route path="/" component={AdminPage} />
<Route path="" component={NotFoundPage} />
</Switch>
</div>
);
}}
</AppLoader>
</div>
);
}

View File

@ -14,6 +14,11 @@ const selectPlugins = () => createSelector(
(appState) => appState.get('plugins')
);
const makeSelectApp = () => createSelector(
selectApp(),
appState => appState.toJS(),
);
const selectHasUserPlugin = () => createSelector(
selectApp(),
(appState) => appState.get('hasUserPlugin'),
@ -38,7 +43,7 @@ const makeSelectAppPlugins = () => createSelector(
selectApp(),
appState => appState.get('appPlugins').toJS(),
);
export default makeSelectApp;
export {
selectApp,
selectHasUserPlugin,

View File

@ -0,0 +1,31 @@
/**
*
* AppLoader
*
*/
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import makeSelectApp from 'containers/App/selectors';
class AppLoader extends React.Component {
shouldLoad = () => {
const { appPlugins, plugins: mountedPlugins } = this.props;
return appPlugins.length !== Object.keys(mountedPlugins).length;
}
render() {
return this.props.children({ shouldLoad: this.shouldLoad() });
}
}
AppLoader.propTypes = {
appPlugins: PropTypes.array.isRequired,
children: PropTypes.func.isRequired,
plugins: PropTypes.object.isRequired,
};
const mapStateToProps = makeSelectApp();
export default connect(mapStateToProps, null)(AppLoader);

View File

@ -51,4 +51,4 @@
"npm": ">= 5.0.0"
},
"license": "MIT"
}
}