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.

108 lines
3.7 KiB

7 years ago
7 years ago
  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. import Favourites from '../features/favourites';
  33. import HashtagTimeline from '../features/hashtag_timeline';
  34. const store = configureStore();
  35. const Mastodon = React.createClass({
  36. propTypes: {
  37. token: React.PropTypes.string.isRequired,
  38. timelines: React.PropTypes.object,
  39. account: React.PropTypes.string
  40. },
  41. mixins: [PureRenderMixin],
  42. componentWillMount() {
  43. store.dispatch(setAccessToken(this.props.token));
  44. store.dispatch(setAccountSelf(JSON.parse(this.props.account)));
  45. if (typeof App !== 'undefined') {
  46. this.subscription = App.cable.subscriptions.create('TimelineChannel', {
  47. received (data) {
  48. switch(data.type) {
  49. case 'update':
  50. return store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
  51. case 'delete':
  52. return store.dispatch(deleteFromTimelines(data.id));
  53. case 'merge':
  54. case 'unmerge':
  55. return store.dispatch(refreshTimeline('home', true));
  56. case 'block':
  57. return store.dispatch(refreshTimeline('mentions', true));
  58. }
  59. }
  60. });
  61. }
  62. },
  63. componentWillUnmount () {
  64. if (typeof this.subscription !== 'undefined') {
  65. this.subscription.unsubscribe();
  66. }
  67. },
  68. render () {
  69. return (
  70. <Provider store={store}>
  71. <Router history={hashHistory} render={applyRouterMiddleware(useScroll())}>
  72. <Route path='/' component={UI}>
  73. <IndexRoute component={GettingStarted} />
  74. <Route path='/statuses/new' component={Compose} />
  75. <Route path='/statuses/home' component={HomeTimeline} />
  76. <Route path='/statuses/mentions' component={MentionsTimeline} />
  77. <Route path='/statuses/all' component={PublicTimeline} />
  78. <Route path='/statuses/tag/:id' component={HashtagTimeline} />
  79. <Route path='/statuses/:statusId' component={Status} />
  80. <Route path='/statuses/:statusId/reblogs' component={Reblogs} />
  81. <Route path='/statuses/:statusId/favourites' component={Favourites} />
  82. <Route path='/accounts/:accountId' component={Account}>
  83. <IndexRoute component={AccountTimeline} />
  84. <Route path='/accounts/:accountId/followers' component={Followers} />
  85. <Route path='/accounts/:accountId/following' component={Following} />
  86. </Route>
  87. </Route>
  88. </Router>
  89. </Provider>
  90. );
  91. }
  92. });
  93. export default Mastodon;