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.

99 lines
3.2 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 UI from '../features/ui';
  19. import Account from '../features/account';
  20. import Status from '../features/status';
  21. import GettingStarted from '../features/getting_started';
  22. import PublicTimeline from '../features/public_timeline';
  23. import AccountTimeline from '../features/account_timeline';
  24. import HomeTimeline from '../features/home_timeline';
  25. import MentionsTimeline from '../features/mentions_timeline';
  26. import Compose from '../features/compose';
  27. const store = configureStore();
  28. const Mastodon = React.createClass({
  29. propTypes: {
  30. token: React.PropTypes.string.isRequired,
  31. timelines: React.PropTypes.object,
  32. account: React.PropTypes.string
  33. },
  34. mixins: [PureRenderMixin],
  35. componentWillMount() {
  36. store.dispatch(setAccessToken(this.props.token));
  37. store.dispatch(setAccountSelf(JSON.parse(this.props.account)));
  38. for (var timelineType in this.props.timelines) {
  39. if (this.props.timelines.hasOwnProperty(timelineType)) {
  40. store.dispatch(refreshTimelineSuccess(timelineType, JSON.parse(this.props.timelines[timelineType])));
  41. }
  42. }
  43. if (typeof App !== 'undefined') {
  44. this.subscription = App.cable.subscriptions.create('TimelineChannel', {
  45. received (data) {
  46. switch(data.type) {
  47. case 'update':
  48. return store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
  49. case 'delete':
  50. return store.dispatch(deleteFromTimelines(data.id));
  51. case 'merge':
  52. case 'unmerge':
  53. return store.dispatch(refreshTimeline('home'));
  54. case 'block':
  55. return store.dispatch(refreshTimeline('mentions'));
  56. }
  57. }
  58. });
  59. }
  60. },
  61. componentWillUnmount () {
  62. if (typeof this.subscription !== 'undefined') {
  63. this.subscription.unsubscribe();
  64. }
  65. },
  66. render () {
  67. return (
  68. <Provider store={store}>
  69. <Router history={hashHistory}>
  70. <Route path='/' component={UI}>
  71. <IndexRoute component={GettingStarted} />
  72. <Route path='/statuses/new' component={Compose} />
  73. <Route path='/statuses/home' component={HomeTimeline} />
  74. <Route path='/statuses/mentions' component={MentionsTimeline} />
  75. <Route path='/statuses/all' component={PublicTimeline} />
  76. <Route path='/statuses/:statusId' component={Status} />
  77. <Route path='/accounts/:accountId' component={Account}>
  78. <IndexRoute component={AccountTimeline} />
  79. </Route>
  80. </Route>
  81. </Router>
  82. </Provider>
  83. );
  84. }
  85. });
  86. export default Mastodon;