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.

64 lines
2.2 KiB

  1. import { Provider } from 'react-redux';
  2. import configureStore from '../store/configureStore';
  3. import Frontend from '../components/frontend';
  4. import { setTimeline, updateTimeline, deleteFromTimelines } from '../actions/timelines';
  5. import { setAccessToken } from '../actions/meta';
  6. import PureRenderMixin from 'react-addons-pure-render-mixin';
  7. import { Router, Route, createMemoryHistory } from 'react-router';
  8. import AccountRoute from '../routes/account_route';
  9. import StatusRoute from '../routes/status_route';
  10. const store = configureStore();
  11. const history = createMemoryHistory();
  12. const Root = React.createClass({
  13. propTypes: {
  14. token: React.PropTypes.string.isRequired,
  15. timelines: React.PropTypes.object
  16. },
  17. mixins: [PureRenderMixin],
  18. componentWillMount() {
  19. store.dispatch(setAccessToken(this.props.token));
  20. for (var timelineType in this.props.timelines) {
  21. if (this.props.timelines.hasOwnProperty(timelineType)) {
  22. store.dispatch(setTimeline(timelineType, JSON.parse(this.props.timelines[timelineType])));
  23. }
  24. }
  25. if (typeof App !== 'undefined') {
  26. App.timeline = App.cable.subscriptions.create("TimelineChannel", {
  27. connected: function() {},
  28. disconnected: function() {},
  29. received: function(data) {
  30. if (data.type === 'update') {
  31. return store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
  32. } else if (data.type === 'delete') {
  33. return store.dispatch(deleteFromTimelines(data.id));
  34. }
  35. }
  36. });
  37. }
  38. },
  39. render () {
  40. return (
  41. <Provider store={store}>
  42. <Router history={history}>
  43. <Route path="/" component={Frontend}>
  44. <Route path="/accounts/:account_id" component={AccountRoute} />
  45. <Route path="/statuses/:status_id" component={StatusRoute} />
  46. </Route>
  47. </Router>
  48. </Provider>
  49. );
  50. }
  51. });
  52. export default Root;