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.

88 lines
2.5 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 {
  13. Router,
  14. Route,
  15. hashHistory,
  16. IndexRoute
  17. } from 'react-router';
  18. import Account from '../features/account';
  19. import Status from '../features/status';
  20. import GettingStarted from '../features/getting_started';
  21. import UI from '../features/ui';
  22. const store = configureStore();
  23. const Mastodon = React.createClass({
  24. propTypes: {
  25. token: React.PropTypes.string.isRequired,
  26. timelines: React.PropTypes.object,
  27. account: React.PropTypes.string
  28. },
  29. mixins: [PureRenderMixin],
  30. componentWillMount() {
  31. store.dispatch(setAccessToken(this.props.token));
  32. store.dispatch(setAccountSelf(JSON.parse(this.props.account)));
  33. for (var timelineType in this.props.timelines) {
  34. if (this.props.timelines.hasOwnProperty(timelineType)) {
  35. store.dispatch(refreshTimelineSuccess(timelineType, JSON.parse(this.props.timelines[timelineType])));
  36. }
  37. }
  38. if (typeof App !== 'undefined') {
  39. App.timeline = App.cable.subscriptions.create("TimelineChannel", {
  40. connected () {
  41. },
  42. disconnected () {
  43. },
  44. received (data) {
  45. switch(data.type) {
  46. case 'update':
  47. return store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
  48. case 'delete':
  49. return store.dispatch(deleteFromTimelines(data.id));
  50. case 'merge':
  51. case 'unmerge':
  52. return store.dispatch(refreshTimeline('home'));
  53. case 'block':
  54. return store.dispatch(refreshTimeline('mentions'));
  55. }
  56. }
  57. });
  58. }
  59. },
  60. render () {
  61. return (
  62. <Provider store={store}>
  63. <Router history={hashHistory}>
  64. <Route path='/' component={UI}>
  65. <IndexRoute component={GettingStarted} />
  66. <Route path='/statuses/:statusId' component={Status} />
  67. <Route path='/accounts/:accountId' component={Account} />
  68. </Route>
  69. </Router>
  70. </Provider>
  71. );
  72. }
  73. });
  74. export default Mastodon;