2017-01-17 13:40:59 +01:00
|
|
|
/**
|
|
|
|
* app.js
|
|
|
|
*
|
|
|
|
* This is the entry file for the application,
|
|
|
|
* only setup and plugin code.
|
|
|
|
*/
|
|
|
|
|
2017-03-18 17:34:00 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { Provider } from 'react-redux';
|
2017-05-11 14:17:21 +02:00
|
|
|
import { syncHistoryWithStore } from 'react-router-redux';
|
2017-06-06 14:22:17 +02:00
|
|
|
import App from 'containers/App'; // eslint-disable-line
|
|
|
|
import { selectLocationState } from 'containers/App/selectors'; // eslint-disable-line
|
2017-05-16 16:32:54 +02:00
|
|
|
import configureStore from 'store';
|
2017-06-06 14:22:17 +02:00
|
|
|
import createRoutes from 'routes';
|
2017-06-20 20:55:58 +02:00
|
|
|
import { translationMessages } from './i18n';
|
2017-01-17 13:40:59 +01:00
|
|
|
|
2017-05-11 15:52:22 +02:00
|
|
|
// Plugin identifier based on the package.json `name` value
|
2017-05-17 11:28:54 +02:00
|
|
|
const pluginPkg = require('../../../../package.json');
|
|
|
|
const pluginId = pluginPkg.name.replace(
|
2017-05-11 15:52:22 +02:00
|
|
|
/^strapi-plugin-/i,
|
|
|
|
''
|
|
|
|
);
|
2017-06-08 17:16:20 +01:00
|
|
|
const pluginName = pluginPkg.strapi.name;
|
|
|
|
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
2017-05-11 15:52:22 +02:00
|
|
|
const apiUrl = window.Strapi && `${window.Strapi.apiUrl}/${pluginId}`;
|
|
|
|
const router = window.Strapi.router;
|
|
|
|
|
2017-01-17 13:40:59 +01:00
|
|
|
// Create redux store with history
|
|
|
|
// this uses the singleton browserHistory provided by react-router
|
|
|
|
// Optionally, this could be changed to leverage a created history
|
|
|
|
// e.g. `const browserHistory = useRouterHistory(createBrowserHistory)();`
|
2017-05-10 11:41:53 +02:00
|
|
|
const store = configureStore({}, window.Strapi.router);
|
|
|
|
|
|
|
|
// Sync history and store, as the react-router-redux reducer
|
|
|
|
// is under the non-default key ("routing"), selectLocationState
|
|
|
|
// must be provided for resolving how to retrieve the "route" in the state
|
|
|
|
syncHistoryWithStore(window.Strapi.router, store, {
|
|
|
|
selectLocationState: selectLocationState(),
|
|
|
|
});
|
2017-01-17 13:40:59 +01:00
|
|
|
|
2017-05-11 15:52:22 +02:00
|
|
|
// Define the plugin root component
|
|
|
|
function Comp(props) {
|
|
|
|
return (
|
|
|
|
<Provider store={store}>
|
|
|
|
<App {...props} />
|
|
|
|
</Provider>
|
|
|
|
);
|
2017-03-18 17:34:00 +01:00
|
|
|
}
|
|
|
|
|
2017-05-11 15:52:22 +02:00
|
|
|
// Add contextTypes to get access to the admin router
|
|
|
|
Comp.contextTypes = {
|
2017-08-18 17:02:33 +02:00
|
|
|
router: React.PropTypes.object.isRequired.isRequired,
|
2017-05-09 17:35:36 +02:00
|
|
|
};
|
|
|
|
|
2017-06-20 20:55:58 +02:00
|
|
|
// Hot reloadable translation json files
|
|
|
|
if (module.hot) {
|
|
|
|
// modules.hot.accept does not accept dynamic dependencies,
|
|
|
|
// have to be constants at compile-time
|
|
|
|
module.hot.accept('./i18n', () => {
|
|
|
|
if (window.Strapi) {
|
|
|
|
System.import('./i18n').then(result => {
|
|
|
|
const translationMessagesUpdated = result.translationMessages;
|
|
|
|
window.Strapi
|
|
|
|
.refresh(pluginId)
|
|
|
|
.translationMessages(translationMessagesUpdated);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-17 13:40:59 +01:00
|
|
|
// Register the plugin
|
2017-05-17 11:28:54 +02:00
|
|
|
window.Strapi.registerPlugin({
|
|
|
|
name: pluginPkg.strapi.name,
|
|
|
|
icon: pluginPkg.strapi.icon,
|
|
|
|
id: pluginId,
|
|
|
|
leftMenuLinks: [],
|
|
|
|
mainComponent: Comp,
|
|
|
|
routes: createRoutes(store),
|
2017-06-20 20:55:58 +02:00
|
|
|
translationMessages,
|
2017-05-17 11:28:54 +02:00
|
|
|
});
|
|
|
|
|
2017-01-17 13:40:59 +01:00
|
|
|
|
|
|
|
// Export store
|
2017-06-08 17:16:20 +01:00
|
|
|
export { store, apiUrl, pluginId, pluginName, pluginDescription, router };
|