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.

67 lines
1.9 KiB

  1. import React from 'react';
  2. import { Provider } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import configureStore from '../store/configureStore';
  5. import { showOnboardingOnce } from '../actions/onboarding';
  6. import { BrowserRouter, Route } from 'react-router-dom';
  7. import { ScrollContext } from 'react-router-scroll-4';
  8. import UI from '../features/ui';
  9. import { fetchCustomEmojis } from '../actions/custom_emojis';
  10. import { hydrateStore } from '../actions/store';
  11. import { connectUserStream } from '../actions/streaming';
  12. import { IntlProvider, addLocaleData } from 'react-intl';
  13. import { getLocale } from '../locales';
  14. import initialState from '../initial_state';
  15. const { localeData, messages } = getLocale();
  16. addLocaleData(localeData);
  17. export const store = configureStore();
  18. const hydrateAction = hydrateStore(initialState);
  19. store.dispatch(hydrateAction);
  20. // load custom emojis
  21. store.dispatch(fetchCustomEmojis());
  22. export default class Mastodon extends React.PureComponent {
  23. static propTypes = {
  24. locale: PropTypes.string.isRequired,
  25. };
  26. componentDidMount() {
  27. this.disconnect = store.dispatch(connectUserStream());
  28. // Desktop notifications
  29. // Ask after 1 minute
  30. if (typeof window.Notification !== 'undefined' && Notification.permission === 'default') {
  31. window.setTimeout(() => Notification.requestPermission(), 60 * 1000);
  32. }
  33. store.dispatch(showOnboardingOnce());
  34. }
  35. componentWillUnmount () {
  36. if (this.disconnect) {
  37. this.disconnect();
  38. this.disconnect = null;
  39. }
  40. }
  41. render () {
  42. const { locale } = this.props;
  43. return (
  44. <IntlProvider locale={locale} messages={messages}>
  45. <Provider store={store}>
  46. <BrowserRouter basename='/web'>
  47. <ScrollContext>
  48. <Route path='/' component={UI} />
  49. </ScrollContext>
  50. </BrowserRouter>
  51. </Provider>
  52. </IntlProvider>
  53. );
  54. }
  55. }