You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.9 KiB
75 lines
2.9 KiB
8 years ago
|
import { Provider } from 'react-redux';
|
||
|
import configureStore from '../store/configureStore';
|
||
|
import { setTimeline, updateTimeline, deleteFromTimelines, refreshTimeline } from '../actions/timelines';
|
||
|
import { setAccessToken } from '../actions/meta';
|
||
8 years ago
|
import { setAccountSelf } from '../actions/accounts';
|
||
8 years ago
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
||
8 years ago
|
import { Router, Route, hashHistory } from 'react-router';
|
||
8 years ago
|
import Account from '../features/account';
|
||
|
import Settings from '../features/settings';
|
||
|
import Status from '../features/status';
|
||
|
import Subscriptions from '../features/subscriptions';
|
||
8 years ago
|
import UI from '../features/ui';
|
||
8 years ago
|
|
||
8 years ago
|
const store = configureStore();
|
||
8 years ago
|
|
||
8 years ago
|
const Mastodon = React.createClass({
|
||
8 years ago
|
|
||
8 years ago
|
propTypes: {
|
||
|
token: React.PropTypes.string.isRequired,
|
||
8 years ago
|
timelines: React.PropTypes.object,
|
||
|
account: React.PropTypes.string
|
||
8 years ago
|
},
|
||
|
|
||
|
mixins: [PureRenderMixin],
|
||
|
|
||
8 years ago
|
componentWillMount() {
|
||
8 years ago
|
store.dispatch(setAccessToken(this.props.token));
|
||
8 years ago
|
store.dispatch(setAccountSelf(JSON.parse(this.props.account)));
|
||
8 years ago
|
|
||
8 years ago
|
for (var timelineType in this.props.timelines) {
|
||
|
if (this.props.timelines.hasOwnProperty(timelineType)) {
|
||
|
store.dispatch(setTimeline(timelineType, JSON.parse(this.props.timelines[timelineType])));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (typeof App !== 'undefined') {
|
||
|
App.timeline = App.cable.subscriptions.create("TimelineChannel", {
|
||
|
connected: function() {},
|
||
|
|
||
|
disconnected: function() {},
|
||
|
|
||
|
received: function(data) {
|
||
8 years ago
|
switch(data.type) {
|
||
|
case 'update':
|
||
|
return store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
|
||
|
case 'delete':
|
||
|
return store.dispatch(deleteFromTimelines(data.id));
|
||
|
case 'merge':
|
||
|
case 'unmerge':
|
||
|
return store.dispatch(refreshTimeline('home'));
|
||
8 years ago
|
}
|
||
8 years ago
|
}
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
|
||
8 years ago
|
render () {
|
||
8 years ago
|
return (
|
||
|
<Provider store={store}>
|
||
8 years ago
|
<Router history={hashHistory}>
|
||
8 years ago
|
<Route path='/' component={UI}>
|
||
8 years ago
|
<Route path='/settings' component={Settings} />
|
||
|
<Route path='/subscriptions' component={Subscriptions} />
|
||
|
<Route path='/statuses/:statusId' component={Status} />
|
||
|
<Route path='/accounts/:accountId' component={Account} />
|
||
8 years ago
|
</Route>
|
||
|
</Router>
|
||
8 years ago
|
</Provider>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
});
|
||
|
|
||
8 years ago
|
export default Mastodon;
|