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.
 
 
 
 

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