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.

122 lines
4.0 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 createBrowserHistory from 'history/lib/createBrowserHistory';
  13. import {
  14. applyRouterMiddleware,
  15. useRouterHistory,
  16. Router,
  17. Route,
  18. IndexRoute
  19. } from 'react-router';
  20. import { useScroll } from 'react-router-scroll';
  21. import UI from '../features/ui';
  22. import Account from '../features/account';
  23. import Status from '../features/status';
  24. import GettingStarted from '../features/getting_started';
  25. import PublicTimeline from '../features/public_timeline';
  26. import AccountTimeline from '../features/account_timeline';
  27. import HomeTimeline from '../features/home_timeline';
  28. import MentionsTimeline from '../features/mentions_timeline';
  29. import Compose from '../features/compose';
  30. import Followers from '../features/followers';
  31. import Following from '../features/following';
  32. import Reblogs from '../features/reblogs';
  33. import Favourites from '../features/favourites';
  34. import HashtagTimeline from '../features/hashtag_timeline';
  35. import { IntlProvider, addLocaleData } from 'react-intl';
  36. import en from 'react-intl/locale-data/en';
  37. const store = configureStore();
  38. const browserHistory = useRouterHistory(createBrowserHistory)({
  39. basename: '/web'
  40. });
  41. addLocaleData([...en]);
  42. const Mastodon = React.createClass({
  43. propTypes: {
  44. token: React.PropTypes.string.isRequired,
  45. timelines: React.PropTypes.object,
  46. account: React.PropTypes.string,
  47. locale: React.PropTypes.string.isRequired
  48. },
  49. mixins: [PureRenderMixin],
  50. componentWillMount() {
  51. store.dispatch(setAccessToken(this.props.token));
  52. store.dispatch(setAccountSelf(JSON.parse(this.props.account)));
  53. if (typeof App !== 'undefined') {
  54. this.subscription = App.cable.subscriptions.create('TimelineChannel', {
  55. received (data) {
  56. switch(data.type) {
  57. case 'update':
  58. return store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
  59. case 'delete':
  60. return store.dispatch(deleteFromTimelines(data.id));
  61. case 'merge':
  62. case 'unmerge':
  63. return store.dispatch(refreshTimeline('home', true));
  64. case 'block':
  65. return store.dispatch(refreshTimeline('mentions', true));
  66. }
  67. }
  68. });
  69. }
  70. },
  71. componentWillUnmount () {
  72. if (typeof this.subscription !== 'undefined') {
  73. this.subscription.unsubscribe();
  74. }
  75. },
  76. render () {
  77. const { locale } = this.props;
  78. return (
  79. <IntlProvider locale={locale}>
  80. <Provider store={store}>
  81. <Router history={browserHistory} render={applyRouterMiddleware(useScroll())}>
  82. <Route path='/' component={UI}>
  83. <IndexRoute component={GettingStarted} />
  84. <Route path='timelines/home' component={HomeTimeline} />
  85. <Route path='timelines/mentions' component={MentionsTimeline} />
  86. <Route path='timelines/public' component={PublicTimeline} />
  87. <Route path='timelines/tag/:id' component={HashtagTimeline} />
  88. <Route path='statuses/new' component={Compose} />
  89. <Route path='statuses/:statusId' component={Status} />
  90. <Route path='statuses/:statusId/reblogs' component={Reblogs} />
  91. <Route path='statuses/:statusId/favourites' component={Favourites} />
  92. <Route path='accounts/:accountId' component={Account}>
  93. <IndexRoute component={AccountTimeline} />
  94. <Route path='followers' component={Followers} />
  95. <Route path='following' component={Following} />
  96. </Route>
  97. </Route>
  98. </Router>
  99. </Provider>
  100. </IntlProvider>
  101. );
  102. }
  103. });
  104. export default Mastodon;