闭社主体 forked from https://github.com/tootsuite/mastodon
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.3 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. const store = configureStore();
  32. const Mastodon = React.createClass({
  33. propTypes: {
  34. token: React.PropTypes.string.isRequired,
  35. timelines: React.PropTypes.object,
  36. account: React.PropTypes.string
  37. },
  38. mixins: [PureRenderMixin],
  39. componentWillMount() {
  40. store.dispatch(setAccessToken(this.props.token));
  41. store.dispatch(setAccountSelf(JSON.parse(this.props.account)));
  42. if (typeof App !== 'undefined') {
  43. this.subscription = App.cable.subscriptions.create('TimelineChannel', {
  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', true));
  53. case 'block':
  54. return store.dispatch(refreshTimeline('mentions', true));
  55. }
  56. }
  57. });
  58. }
  59. },
  60. componentWillUnmount () {
  61. if (typeof this.subscription !== 'undefined') {
  62. this.subscription.unsubscribe();
  63. }
  64. },
  65. render () {
  66. return (
  67. <Provider store={store}>
  68. <Router history={hashHistory} render={applyRouterMiddleware(useScroll())}>
  69. <Route path='/' component={UI}>
  70. <IndexRoute component={GettingStarted} />
  71. <Route path='/statuses/new' component={Compose} />
  72. <Route path='/statuses/home' component={HomeTimeline} />
  73. <Route path='/statuses/mentions' component={MentionsTimeline} />
  74. <Route path='/statuses/all' component={PublicTimeline} />
  75. <Route path='/statuses/:statusId' component={Status} />
  76. <Route path='/accounts/:accountId' component={Account}>
  77. <IndexRoute component={AccountTimeline} />
  78. <Route path='/accounts/:accountId/followers' component={Followers} />
  79. <Route path='/accounts/:accountId/following' component={Following} />
  80. </Route>
  81. </Route>
  82. </Router>
  83. </Provider>
  84. );
  85. }
  86. });
  87. export default Mastodon;