2015-12-28 23:34:32 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { render } from 'react-dom';
|
2016-01-15 19:56:03 +00:00
|
|
|
import { browserHistory } from 'react-router';
|
2016-03-14 22:22:24 +00:00
|
|
|
import { syncHistoryWithStore, replace } from 'react-router-redux';
|
2017-04-11 22:00:59 +00:00
|
|
|
import { AppContainer } from 'react-hot-loader';
|
2017-02-16 02:55:50 +00:00
|
|
|
import 'react-virtualized/styles.css';
|
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
import configureStore from './store';
|
|
|
|
import createRoutes from './routes';
|
|
|
|
import Socket from './util/Socket';
|
|
|
|
import handleSocket from './socket';
|
|
|
|
import Root from './containers/Root';
|
2017-04-19 23:51:55 +00:00
|
|
|
import { addMessages } from './actions/message';
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2017-02-16 02:55:50 +00:00
|
|
|
const host = DEV ? `${window.location.hostname}:1337` : window.location.host;
|
2016-01-15 01:27:30 +00:00
|
|
|
const socket = new Socket(host);
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2016-01-15 19:56:03 +00:00
|
|
|
const store = configureStore(socket, browserHistory);
|
2016-01-26 21:10:44 +00:00
|
|
|
|
2016-02-03 18:42:07 +00:00
|
|
|
const env = JSON.parse(document.getElementById('env').innerHTML);
|
|
|
|
|
|
|
|
// TODO: Handle this properly
|
2017-02-16 02:55:50 +00:00
|
|
|
window.ENV = {
|
2016-02-03 18:42:07 +00:00
|
|
|
defaults: env.defaults
|
|
|
|
};
|
|
|
|
|
|
|
|
if (env.servers) {
|
2016-01-26 21:10:44 +00:00
|
|
|
store.dispatch({
|
|
|
|
type: 'SOCKET_SERVERS',
|
2016-02-03 18:42:07 +00:00
|
|
|
data: env.servers
|
2016-01-26 21:10:44 +00:00
|
|
|
});
|
|
|
|
} else {
|
2016-03-14 22:22:24 +00:00
|
|
|
store.dispatch(replace('/connect'));
|
2016-01-26 21:10:44 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 18:42:07 +00:00
|
|
|
if (env.channels) {
|
2016-01-26 21:10:44 +00:00
|
|
|
store.dispatch({
|
|
|
|
type: 'SOCKET_CHANNELS',
|
2016-02-03 18:42:07 +00:00
|
|
|
data: env.channels
|
2016-01-26 21:10:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-03 18:42:07 +00:00
|
|
|
if (env.users) {
|
2016-01-26 21:10:44 +00:00
|
|
|
store.dispatch({
|
|
|
|
type: 'SOCKET_USERS',
|
2016-02-03 18:42:07 +00:00
|
|
|
...env.users
|
2016-01-26 21:10:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-19 23:51:55 +00:00
|
|
|
if (env.messages) {
|
2017-05-02 21:21:25 +00:00
|
|
|
const { messages, server, to, next } = env.messages;
|
|
|
|
store.dispatch(addMessages(messages, server, to, false, next));
|
2017-04-19 23:51:55 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 19:56:03 +00:00
|
|
|
handleSocket(socket, store);
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2015-12-29 21:23:07 +00:00
|
|
|
const routes = createRoutes();
|
2016-03-14 22:22:24 +00:00
|
|
|
const history = syncHistoryWithStore(browserHistory, store);
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2017-04-11 22:00:59 +00:00
|
|
|
const renderRoot = () => {
|
|
|
|
render(
|
|
|
|
<AppContainer>
|
|
|
|
<Root store={store} routes={routes} history={history} />
|
|
|
|
</AppContainer>,
|
|
|
|
document.getElementById('root')
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
renderRoot();
|
|
|
|
|
|
|
|
if (module.hot) {
|
|
|
|
module.hot.accept('./routes', () => renderRoot());
|
|
|
|
}
|