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.

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