The code powering m.abunchtell.com https://m.abunchtell.com
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

140 Zeilen
4.7 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 fr from 'react-intl/locale-data/fr';
  42. import getMessagesForLocale from '../locales';
  43. const store = configureStore();
  44. const browserHistory = useRouterHistory(createBrowserHistory)({
  45. basename: '/web'
  46. });
  47. addLocaleData([...en, ...de, ...es, ...fr]);
  48. const Mastodon = React.createClass({
  49. propTypes: {
  50. token: React.PropTypes.string.isRequired,
  51. timelines: React.PropTypes.object,
  52. account: React.PropTypes.string,
  53. locale: React.PropTypes.string.isRequired
  54. },
  55. mixins: [PureRenderMixin],
  56. componentWillMount() {
  57. const { token, account, locale } = this.props;
  58. store.dispatch(setAccessToken(token));
  59. store.dispatch(setAccountSelf(JSON.parse(account)));
  60. if (typeof App !== 'undefined') {
  61. this.subscription = App.cable.subscriptions.create('TimelineChannel', {
  62. received (data) {
  63. switch(data.type) {
  64. case 'update':
  65. return store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
  66. case 'delete':
  67. return store.dispatch(deleteFromTimelines(data.id));
  68. case 'merge':
  69. case 'unmerge':
  70. return store.dispatch(refreshTimeline('home', true));
  71. case 'block':
  72. return store.dispatch(refreshTimeline('mentions', true));
  73. case 'notification':
  74. return store.dispatch(updateNotifications(JSON.parse(data.message), getMessagesForLocale(locale), locale));
  75. }
  76. }
  77. });
  78. }
  79. // Desktop notifications
  80. if (typeof window.Notification !== 'undefined' && Notification.permission === 'default') {
  81. Notification.requestPermission();
  82. }
  83. },
  84. componentWillUnmount () {
  85. if (typeof this.subscription !== 'undefined') {
  86. this.subscription.unsubscribe();
  87. }
  88. },
  89. render () {
  90. const { locale } = this.props;
  91. return (
  92. <IntlProvider locale={locale} messages={getMessagesForLocale(locale)}>
  93. <Provider store={store}>
  94. <Router history={browserHistory} render={applyRouterMiddleware(useScroll())}>
  95. <Route path='/' component={UI}>
  96. <IndexRoute component={GettingStarted} />
  97. <Route path='timelines/home' component={HomeTimeline} />
  98. <Route path='timelines/mentions' component={MentionsTimeline} />
  99. <Route path='timelines/public' component={PublicTimeline} />
  100. <Route path='timelines/tag/:id' component={HashtagTimeline} />
  101. <Route path='notifications' component={Notifications} />
  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>
  112. </Router>
  113. </Provider>
  114. </IntlProvider>
  115. );
  116. }
  117. });
  118. export default Mastodon;