The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

148 lines
5.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 { updateNotifications, refreshNotifications } 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 Status from '../features/status';
  22. import GettingStarted from '../features/getting_started';
  23. import PublicTimeline from '../features/public_timeline';
  24. import AccountTimeline from '../features/account_timeline';
  25. import HomeTimeline from '../features/home_timeline';
  26. import Compose from '../features/compose';
  27. import Followers from '../features/followers';
  28. import Following from '../features/following';
  29. import Reblogs from '../features/reblogs';
  30. import Favourites from '../features/favourites';
  31. import HashtagTimeline from '../features/hashtag_timeline';
  32. import Notifications from '../features/notifications';
  33. import FollowRequests from '../features/follow_requests';
  34. import GenericNotFound from '../features/generic_not_found';
  35. import FavouritedStatuses from '../features/favourited_statuses';
  36. import Blocks from '../features/blocks';
  37. import Report from '../features/report';
  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. import createStream from '../stream';
  49. const store = configureStore();
  50. store.dispatch(hydrateStore(window.INITIAL_STATE));
  51. const browserHistory = useRouterHistory(createBrowserHistory)({
  52. basename: '/web'
  53. });
  54. addLocaleData([...en, ...de, ...es, ...fr, ...pt, ...hu, ...uk]);
  55. const Mastodon = React.createClass({
  56. propTypes: {
  57. locale: React.PropTypes.string.isRequired
  58. },
  59. componentDidMount() {
  60. const { locale } = this.props;
  61. const accessToken = store.getState().getIn(['meta', 'access_token']);
  62. this.subscription = createStream(accessToken, 'user', {
  63. received (data) {
  64. switch(data.event) {
  65. case 'update':
  66. store.dispatch(updateTimeline('home', JSON.parse(data.payload)));
  67. break;
  68. case 'delete':
  69. store.dispatch(deleteFromTimelines(data.payload));
  70. break;
  71. case 'notification':
  72. store.dispatch(updateNotifications(JSON.parse(data.payload), getMessagesForLocale(locale), locale));
  73. break;
  74. }
  75. },
  76. reconnected () {
  77. store.dispatch(refreshTimeline('home'));
  78. store.dispatch(refreshNotifications());
  79. }
  80. });
  81. // Desktop notifications
  82. if (typeof window.Notification !== 'undefined' && Notification.permission === 'default') {
  83. Notification.requestPermission();
  84. }
  85. },
  86. componentWillUnmount () {
  87. if (typeof this.subscription !== 'undefined') {
  88. this.subscription.close();
  89. this.subscription = null;
  90. }
  91. },
  92. render () {
  93. const { locale } = this.props;
  94. return (
  95. <IntlProvider locale={locale} messages={getMessagesForLocale(locale)}>
  96. <Provider store={store}>
  97. <Router history={browserHistory} render={applyRouterMiddleware(useScroll())}>
  98. <Route path='/' component={UI}>
  99. <IndexRedirect to="/getting-started" />
  100. <Route path='getting-started' component={GettingStarted} />
  101. <Route path='timelines/home' component={HomeTimeline} />
  102. <Route path='timelines/public' component={PublicTimeline} />
  103. <Route path='timelines/tag/:id' component={HashtagTimeline} />
  104. <Route path='notifications' component={Notifications} />
  105. <Route path='favourites' component={FavouritedStatuses} />
  106. <Route path='statuses/new' component={Compose} />
  107. <Route path='statuses/:statusId' component={Status} />
  108. <Route path='statuses/:statusId/reblogs' component={Reblogs} />
  109. <Route path='statuses/:statusId/favourites' component={Favourites} />
  110. <Route path='accounts/:accountId' component={AccountTimeline} />
  111. <Route path='accounts/:accountId/followers' component={Followers} />
  112. <Route path='accounts/:accountId/following' component={Following} />
  113. <Route path='follow_requests' component={FollowRequests} />
  114. <Route path='blocks' component={Blocks} />
  115. <Route path='report' component={Report} />
  116. <Route path='*' component={GenericNotFound} />
  117. </Route>
  118. </Router>
  119. </Provider>
  120. </IntlProvider>
  121. );
  122. }
  123. });
  124. export default Mastodon;