闭社主体 forked from https://github.com/tootsuite/mastodon
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.

64 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 { 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 initialState from '../initial_state';
  14. import ErrorBoundary from '../components/error_boundary';
  15. const { localeData, messages } = getLocale();
  16. addLocaleData(localeData);
  17. export const store = configureStore();
  18. const hydrateAction = hydrateStore(initialState);
  19. store.dispatch(hydrateAction);
  20. store.dispatch(fetchCustomEmojis());
  21. export default class Mastodon extends React.PureComponent {
  22. static propTypes = {
  23. locale: PropTypes.string.isRequired,
  24. };
  25. componentDidMount() {
  26. this.disconnect = store.dispatch(connectUserStream());
  27. }
  28. componentWillUnmount () {
  29. if (this.disconnect) {
  30. this.disconnect();
  31. this.disconnect = null;
  32. }
  33. }
  34. shouldUpdateScroll (prevRouterProps, { location }) {
  35. return !(location.state?.mastodonModalKey && location.state?.mastodonModalKey !== prevRouterProps?.location?.state?.mastodonModalKey);
  36. }
  37. render () {
  38. const { locale } = this.props;
  39. return (
  40. <IntlProvider locale={locale} messages={messages}>
  41. <Provider store={store}>
  42. <ErrorBoundary>
  43. <BrowserRouter basename='/web'>
  44. <ScrollContext shouldUpdateScroll={this.shouldUpdateScroll}>
  45. <Route path='/' component={UI} />
  46. </ScrollContext>
  47. </BrowserRouter>
  48. </ErrorBoundary>
  49. </Provider>
  50. </IntlProvider>
  51. );
  52. }
  53. }