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.

79 lines
2.6 KiB

  1. import { Provider } from 'react-redux';
  2. import configureStore from '../store/configureStore';
  3. import {
  4. refreshTimelineSuccess,
  5. updateTimeline,
  6. deleteFromTimelines,
  7. refreshTimeline
  8. } from '../actions/timelines';
  9. import { setAccessToken } from '../actions/meta';
  10. import { setAccountSelf } from '../actions/accounts';
  11. import PureRenderMixin from 'react-addons-pure-render-mixin';
  12. import { Router, Route, hashHistory } from 'react-router';
  13. import Account from '../features/account';
  14. import Settings from '../features/settings';
  15. import Status from '../features/status';
  16. import Subscriptions from '../features/subscriptions';
  17. import UI from '../features/ui';
  18. const store = configureStore();
  19. const Mastodon = React.createClass({
  20. propTypes: {
  21. token: React.PropTypes.string.isRequired,
  22. timelines: React.PropTypes.object,
  23. account: React.PropTypes.string
  24. },
  25. mixins: [PureRenderMixin],
  26. componentWillMount() {
  27. store.dispatch(setAccessToken(this.props.token));
  28. store.dispatch(setAccountSelf(JSON.parse(this.props.account)));
  29. for (var timelineType in this.props.timelines) {
  30. if (this.props.timelines.hasOwnProperty(timelineType)) {
  31. store.dispatch(refreshTimelineSuccess(timelineType, JSON.parse(this.props.timelines[timelineType])));
  32. }
  33. }
  34. if (typeof App !== 'undefined') {
  35. App.timeline = App.cable.subscriptions.create("TimelineChannel", {
  36. connected: function() {},
  37. disconnected: function() {},
  38. received: function(data) {
  39. switch(data.type) {
  40. case 'update':
  41. return store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
  42. case 'delete':
  43. return store.dispatch(deleteFromTimelines(data.id));
  44. case 'merge':
  45. case 'unmerge':
  46. return store.dispatch(refreshTimeline('home'));
  47. }
  48. }
  49. });
  50. }
  51. },
  52. render () {
  53. return (
  54. <Provider store={store}>
  55. <Router history={hashHistory}>
  56. <Route path='/' component={UI}>
  57. <Route path='/settings' component={Settings} />
  58. <Route path='/subscriptions' component={Subscriptions} />
  59. <Route path='/statuses/:statusId' component={Status} />
  60. <Route path='/accounts/:accountId' component={Account} />
  61. </Route>
  62. </Router>
  63. </Provider>
  64. );
  65. }
  66. });
  67. export default Mastodon;