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.

66 lines
2.0 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 { BrowserRouter, Route } from 'react-router-dom';
  6. import { ScrollContext } from 'react-router-scroll-4';
  7. import UI from '../features/ui';
  8. import { fetchCustomEmojis } from '../actions/custom_emojis';
  9. import { hydrateStore } from '../actions/store';
  10. import { connectUserStream } from '../actions/streaming';
  11. import { IntlProvider, addLocaleData } from 'react-intl';
  12. import { getLocale } from '../locales';
  13. import { previewState as previewMediaState } from 'mastodon/features/ui/components/media_modal';
  14. import { previewState as previewVideoState } from 'mastodon/features/ui/components/video_modal';
  15. import initialState from '../initial_state';
  16. import ErrorBoundary from '../components/error_boundary';
  17. const { localeData, messages } = getLocale();
  18. addLocaleData(localeData);
  19. export const store = configureStore();
  20. const hydrateAction = hydrateStore(initialState);
  21. store.dispatch(hydrateAction);
  22. store.dispatch(fetchCustomEmojis());
  23. export default class Mastodon extends React.PureComponent {
  24. static propTypes = {
  25. locale: PropTypes.string.isRequired,
  26. };
  27. componentDidMount() {
  28. this.disconnect = store.dispatch(connectUserStream());
  29. }
  30. componentWillUnmount () {
  31. if (this.disconnect) {
  32. this.disconnect();
  33. this.disconnect = null;
  34. }
  35. }
  36. shouldUpdateScroll (_, { location }) {
  37. return location.state !== previewMediaState && location.state !== previewVideoState;
  38. }
  39. render () {
  40. const { locale } = this.props;
  41. return (
  42. <IntlProvider locale={locale} messages={messages}>
  43. <Provider store={store}>
  44. <ErrorBoundary>
  45. <BrowserRouter basename='/web'>
  46. <ScrollContext shouldUpdateScroll={this.shouldUpdateScroll}>
  47. <Route path='/' component={UI} />
  48. </ScrollContext>
  49. </BrowserRouter>
  50. </ErrorBoundary>
  51. </Provider>
  52. </IntlProvider>
  53. );
  54. }
  55. }