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.

101 lines
3.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. applyRouterMiddleware,
  14. Router,
  15. Route,
  16. hashHistory,
  17. IndexRoute
  18. } from 'react-router';
  19. import { useScroll } from 'react-router-scroll';
  20. import UI from '../features/ui';
  21. import Account from '../features/account';
  22. import Status from '../features/status';
  23. import GettingStarted from '../features/getting_started';
  24. import PublicTimeline from '../features/public_timeline';
  25. import AccountTimeline from '../features/account_timeline';
  26. import HomeTimeline from '../features/home_timeline';
  27. import MentionsTimeline from '../features/mentions_timeline';
  28. import Compose from '../features/compose';
  29. import Followers from '../features/followers';
  30. import Following from '../features/following';
  31. import Reblogs from '../features/reblogs';
  32. const store = configureStore();
  33. const Mastodon = React.createClass({
  34. propTypes: {
  35. token: React.PropTypes.string.isRequired,
  36. timelines: React.PropTypes.object,
  37. account: React.PropTypes.string
  38. },
  39. mixins: [PureRenderMixin],
  40. componentWillMount() {
  41. store.dispatch(setAccessToken(this.props.token));
  42. store.dispatch(setAccountSelf(JSON.parse(this.props.account)));
  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', true));
  54. case 'block':
  55. return store.dispatch(refreshTimeline('mentions', true));
  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} render={applyRouterMiddleware(useScroll())}>
  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='/statuses/:statusId/reblogs' component={Reblogs} />
  78. <Route path='/accounts/:accountId' component={Account}>
  79. <IndexRoute component={AccountTimeline} />
  80. <Route path='/accounts/:accountId/followers' component={Followers} />
  81. <Route path='/accounts/:accountId/following' component={Following} />
  82. </Route>
  83. </Route>
  84. </Router>
  85. </Provider>
  86. );
  87. }
  88. });
  89. export default Mastodon;