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.

84 lines
2.1 KiB

  1. import React from 'react';
  2. import { Provider, connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import configureStore from '../store/configureStore';
  5. import { INTRODUCTION_VERSION } 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 Introduction from '../features/introduction';
  10. import { fetchCustomEmojis } from '../actions/custom_emojis';
  11. import { hydrateStore } from '../actions/store';
  12. import { connectUserStream } from '../actions/streaming';
  13. import { IntlProvider, addLocaleData } from 'react-intl';
  14. import { getLocale } from '../locales';
  15. import initialState from '../initial_state';
  16. const { localeData, messages } = getLocale();
  17. addLocaleData(localeData);
  18. export const store = configureStore();
  19. const hydrateAction = hydrateStore(initialState);
  20. store.dispatch(hydrateAction);
  21. store.dispatch(fetchCustomEmojis());
  22. const mapStateToProps = state => ({
  23. showIntroduction: state.getIn(['settings', 'introductionVersion'], 0) < INTRODUCTION_VERSION,
  24. });
  25. @connect(mapStateToProps)
  26. class MastodonMount extends React.PureComponent {
  27. static propTypes = {
  28. showIntroduction: PropTypes.bool,
  29. };
  30. render () {
  31. const { showIntroduction } = this.props;
  32. if (showIntroduction) {
  33. return <Introduction />;
  34. }
  35. return (
  36. <BrowserRouter basename='/web'>
  37. <ScrollContext>
  38. <Route path='/' component={UI} />
  39. </ScrollContext>
  40. </BrowserRouter>
  41. );
  42. }
  43. }
  44. export default class Mastodon extends React.PureComponent {
  45. static propTypes = {
  46. locale: PropTypes.string.isRequired,
  47. };
  48. componentDidMount() {
  49. this.disconnect = store.dispatch(connectUserStream());
  50. }
  51. componentWillUnmount () {
  52. if (this.disconnect) {
  53. this.disconnect();
  54. this.disconnect = null;
  55. }
  56. }
  57. render () {
  58. const { locale } = this.props;
  59. return (
  60. <IntlProvider locale={locale} messages={messages}>
  61. <Provider store={store}>
  62. <MastodonMount />
  63. </Provider>
  64. </IntlProvider>
  65. );
  66. }
  67. }