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.

141 lines
4.9 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 { updateNotifications } from '../actions/notifications';
  10. import createBrowserHistory from 'history/lib/createBrowserHistory';
  11. import {
  12. applyRouterMiddleware,
  13. useRouterHistory,
  14. Router,
  15. Route,
  16. IndexRedirect,
  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. import Notifications from '../features/notifications';
  35. import FollowRequests from '../features/follow_requests';
  36. import GenericNotFound from '../features/generic_not_found';
  37. import FavouritedStatuses from '../features/favourited_statuses';
  38. import { IntlProvider, addLocaleData } from 'react-intl';
  39. import en from 'react-intl/locale-data/en';
  40. import de from 'react-intl/locale-data/de';
  41. import es from 'react-intl/locale-data/es';
  42. import fr from 'react-intl/locale-data/fr';
  43. import pt from 'react-intl/locale-data/pt';
  44. import hu from 'react-intl/locale-data/hu';
  45. import uk from 'react-intl/locale-data/uk';
  46. import getMessagesForLocale from '../locales';
  47. import { hydrateStore } from '../actions/store';
  48. const store = configureStore();
  49. store.dispatch(hydrateStore(window.INITIAL_STATE));
  50. const browserHistory = useRouterHistory(createBrowserHistory)({
  51. basename: '/web'
  52. });
  53. addLocaleData([...en, ...de, ...es, ...fr, ...pt, ...hu, ...uk]);
  54. const Mastodon = React.createClass({
  55. propTypes: {
  56. locale: React.PropTypes.string.isRequired
  57. },
  58. componentWillMount() {
  59. const { locale } = this.props;
  60. if (typeof App !== 'undefined') {
  61. this.subscription = App.cable.subscriptions.create('TimelineChannel', {
  62. received (data) {
  63. switch(data.type) {
  64. case 'update':
  65. store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
  66. break;
  67. case 'delete':
  68. store.dispatch(deleteFromTimelines(data.id));
  69. break;
  70. case 'notification':
  71. store.dispatch(updateNotifications(JSON.parse(data.message), getMessagesForLocale(locale), locale));
  72. break;
  73. }
  74. }
  75. });
  76. }
  77. // Desktop notifications
  78. if (typeof window.Notification !== 'undefined' && Notification.permission === 'default') {
  79. Notification.requestPermission();
  80. }
  81. },
  82. componentWillUnmount () {
  83. if (typeof this.subscription !== 'undefined') {
  84. this.subscription.unsubscribe();
  85. }
  86. },
  87. render () {
  88. const { locale } = this.props;
  89. return (
  90. <IntlProvider locale={locale} messages={getMessagesForLocale(locale)}>
  91. <Provider store={store}>
  92. <Router history={browserHistory} render={applyRouterMiddleware(useScroll())}>
  93. <Route path='/' component={UI}>
  94. <IndexRedirect to="/getting-started" />
  95. <Route path='getting-started' component={GettingStarted} />
  96. <Route path='timelines/home' component={HomeTimeline} />
  97. <Route path='timelines/mentions' component={MentionsTimeline} />
  98. <Route path='timelines/public' component={PublicTimeline} />
  99. <Route path='timelines/tag/:id' component={HashtagTimeline} />
  100. <Route path='notifications' component={Notifications} />
  101. <Route path='favourites' component={FavouritedStatuses} />
  102. <Route path='statuses/new' component={Compose} />
  103. <Route path='statuses/:statusId' component={Status} />
  104. <Route path='statuses/:statusId/reblogs' component={Reblogs} />
  105. <Route path='statuses/:statusId/favourites' component={Favourites} />
  106. <Route path='accounts/:accountId' component={Account}>
  107. <IndexRoute component={AccountTimeline} />
  108. <Route path='followers' component={Followers} />
  109. <Route path='following' component={Following} />
  110. </Route>
  111. <Route path='follow_requests' component={FollowRequests} />
  112. <Route path='*' component={GenericNotFound} />
  113. </Route>
  114. </Router>
  115. </Provider>
  116. </IntlProvider>
  117. );
  118. }
  119. });
  120. export default Mastodon;