Improve initialState loading
This commit is contained in:
parent
2e71bb031b
commit
23ebf60b95
11 changed files with 108 additions and 90 deletions
|
@ -7,8 +7,6 @@ import {
|
|||
refreshTimeline
|
||||
} from '../actions/timelines';
|
||||
import { updateNotifications } from '../actions/notifications';
|
||||
import { setAccessToken } from '../actions/meta';
|
||||
import { setAccountSelf } from '../actions/accounts';
|
||||
import createBrowserHistory from 'history/lib/createBrowserHistory';
|
||||
import {
|
||||
applyRouterMiddleware,
|
||||
|
@ -44,9 +42,12 @@ import pt from 'react-intl/locale-data/pt';
|
|||
import hu from 'react-intl/locale-data/hu';
|
||||
import uk from 'react-intl/locale-data/uk';
|
||||
import getMessagesForLocale from '../locales';
|
||||
import { hydrateStore } from '../actions/store';
|
||||
|
||||
const store = configureStore();
|
||||
|
||||
store.dispatch(hydrateStore(window.INITIAL_STATE));
|
||||
|
||||
const browserHistory = useRouterHistory(createBrowserHistory)({
|
||||
basename: '/web'
|
||||
});
|
||||
|
@ -56,29 +57,26 @@ addLocaleData([...en, ...de, ...es, ...fr, ...pt, ...hu, ...uk]);
|
|||
const Mastodon = React.createClass({
|
||||
|
||||
propTypes: {
|
||||
token: React.PropTypes.string.isRequired,
|
||||
timelines: React.PropTypes.object,
|
||||
account: React.PropTypes.string,
|
||||
locale: React.PropTypes.string.isRequired
|
||||
},
|
||||
|
||||
componentWillMount() {
|
||||
const { token, account, locale } = this.props;
|
||||
|
||||
store.dispatch(setAccessToken(token));
|
||||
store.dispatch(setAccountSelf(JSON.parse(account)));
|
||||
const { locale } = this.props;
|
||||
|
||||
if (typeof App !== 'undefined') {
|
||||
this.subscription = App.cable.subscriptions.create('TimelineChannel', {
|
||||
|
||||
received (data) {
|
||||
switch(data.type) {
|
||||
case 'update':
|
||||
return store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
|
||||
case 'delete':
|
||||
return store.dispatch(deleteFromTimelines(data.id));
|
||||
case 'notification':
|
||||
return store.dispatch(updateNotifications(JSON.parse(data.message), getMessagesForLocale(locale), locale));
|
||||
case 'update':
|
||||
store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
|
||||
break;
|
||||
case 'delete':
|
||||
store.dispatch(deleteFromTimelines(data.id));
|
||||
break;
|
||||
case 'notification':
|
||||
store.dispatch(updateNotifications(JSON.parse(data.message), getMessagesForLocale(locale), locale));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue