2018-02-28 15:45:16 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { render } from 'react-dom';
|
2019-11-14 11:25:04 +02:00
|
|
|
import { Provider, connect } from 'react-redux';
|
2021-03-11 15:40:12 +02:00
|
|
|
import { Route, Router } from 'react-router-dom';
|
2019-03-18 12:47:58 -07:00
|
|
|
import store from 'ReduxStore';
|
2021-03-11 15:40:12 +02:00
|
|
|
import history from 'Routing/history';
|
2021-01-13 19:51:45 +02:00
|
|
|
import { loadConfig } from 'Actions/config';
|
2021-01-18 11:37:12 +02:00
|
|
|
import { authenticateUser } from 'Actions/auth';
|
2019-11-14 11:25:04 +02:00
|
|
|
import { getPhrases } from 'Lib/phrases';
|
2019-12-18 18:16:02 +02:00
|
|
|
import { selectLocale } from 'Reducers/config';
|
2018-11-02 14:19:49 -03:00
|
|
|
import { I18n } from 'react-polyglot';
|
2019-03-15 10:19:57 -04:00
|
|
|
import { GlobalStyles } from 'netlify-cms-ui-default';
|
2018-08-07 14:46:54 -06:00
|
|
|
import { ErrorBoundary } from 'UI';
|
2018-02-28 15:45:16 -05:00
|
|
|
import App from 'App/App';
|
|
|
|
import 'EditorWidgets';
|
2019-03-16 15:44:29 -07:00
|
|
|
import 'coreSrc/mediaLibrary';
|
2018-07-06 18:56:28 -04:00
|
|
|
import 'what-input';
|
2018-02-28 15:45:16 -05:00
|
|
|
|
2018-03-28 15:52:57 -04:00
|
|
|
const ROOT_ID = 'nc-root';
|
2018-03-06 17:14:09 -05:00
|
|
|
|
2021-02-08 20:01:21 +02:00
|
|
|
function TranslatedApp({ locale, config }) {
|
2019-11-14 11:25:04 +02:00
|
|
|
return (
|
|
|
|
<I18n locale={locale} messages={getPhrases(locale)}>
|
2020-03-22 16:04:11 +02:00
|
|
|
<ErrorBoundary showBackup config={config}>
|
2021-03-11 15:40:12 +02:00
|
|
|
<Router history={history}>
|
2019-11-14 11:25:04 +02:00
|
|
|
<Route component={App} />
|
2021-03-11 15:40:12 +02:00
|
|
|
</Router>
|
2019-11-14 11:25:04 +02:00
|
|
|
</ErrorBoundary>
|
|
|
|
</I18n>
|
|
|
|
);
|
2021-02-08 20:01:21 +02:00
|
|
|
}
|
2019-11-14 11:25:04 +02:00
|
|
|
|
2021-02-08 20:01:21 +02:00
|
|
|
function mapDispatchToProps(state) {
|
2020-03-22 16:04:11 +02:00
|
|
|
return { locale: selectLocale(state.config), config: state.config };
|
2021-02-08 20:01:21 +02:00
|
|
|
}
|
2019-11-14 11:25:04 +02:00
|
|
|
|
|
|
|
const ConnectedTranslatedApp = connect(mapDispatchToProps)(TranslatedApp);
|
|
|
|
|
2018-03-28 15:52:57 -04:00
|
|
|
function bootstrap(opts = {}) {
|
2018-03-06 17:14:09 -05:00
|
|
|
const { config } = opts;
|
|
|
|
|
2018-02-28 15:45:16 -05:00
|
|
|
/**
|
|
|
|
* Log the version number.
|
|
|
|
*/
|
2019-03-22 08:24:46 -07:00
|
|
|
if (typeof NETLIFY_CMS_CORE_VERSION === 'string') {
|
2018-07-27 14:26:03 -04:00
|
|
|
console.log(`netlify-cms-core ${NETLIFY_CMS_CORE_VERSION}`);
|
|
|
|
}
|
2018-02-28 15:45:16 -05:00
|
|
|
|
|
|
|
/**
|
2018-03-28 15:52:57 -04:00
|
|
|
* Get DOM element where app will mount.
|
2018-02-28 15:45:16 -05:00
|
|
|
*/
|
2018-03-28 15:52:57 -04:00
|
|
|
function getRoot() {
|
|
|
|
/**
|
|
|
|
* Return existing root if found.
|
|
|
|
*/
|
|
|
|
const existingRoot = document.getElementById(ROOT_ID);
|
|
|
|
if (existingRoot) {
|
|
|
|
return existingRoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If no existing root, create and return a new root.
|
|
|
|
*/
|
|
|
|
const newRoot = document.createElement('div');
|
|
|
|
newRoot.id = ROOT_ID;
|
|
|
|
document.body.appendChild(newRoot);
|
|
|
|
return newRoot;
|
|
|
|
}
|
2018-02-28 15:45:16 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch config to store if received. This config will be merged into
|
|
|
|
* config.yml if it exists, and any portion that produces a conflict will be
|
|
|
|
* overwritten.
|
|
|
|
*/
|
2021-01-18 11:37:12 +02:00
|
|
|
store.dispatch(
|
|
|
|
loadConfig(config, function onLoad() {
|
|
|
|
store.dispatch(authenticateUser());
|
|
|
|
}),
|
|
|
|
);
|
2018-02-28 15:45:16 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create connected root component.
|
|
|
|
*/
|
2021-02-08 20:01:21 +02:00
|
|
|
function Root() {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<GlobalStyles />
|
|
|
|
<Provider store={store}>
|
|
|
|
<ConnectedTranslatedApp />
|
|
|
|
</Provider>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2018-02-28 15:45:16 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Render application root.
|
|
|
|
*/
|
2018-03-28 15:52:57 -04:00
|
|
|
render(<Root />, getRoot());
|
2018-02-28 15:45:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export default bootstrap;
|