mirror of
https://github.com/mastodon/mastodon.git
synced 2025-11-29 10:53:39 +00:00
71 lines
2.1 KiB
JavaScript
71 lines
2.1 KiB
JavaScript
import { PureComponent } from 'react';
|
|
|
|
import { Helmet } from 'react-helmet';
|
|
import { Route } from 'react-router-dom';
|
|
|
|
import { Provider as ReduxProvider } from 'react-redux';
|
|
|
|
|
|
import { fetchCustomEmojis } from 'mastodon/actions/custom_emojis';
|
|
import { hydrateStore } from 'mastodon/actions/store';
|
|
import { connectUserStream } from 'mastodon/actions/streaming';
|
|
import ErrorBoundary from 'mastodon/components/error_boundary';
|
|
import { Router } from 'mastodon/components/router';
|
|
import UI from 'mastodon/features/ui';
|
|
import { IdentityContext, createIdentityContext } from 'mastodon/identity_context';
|
|
import { initialState, title as siteTitle } from 'mastodon/initial_state';
|
|
import { IntlProvider } from 'mastodon/locales';
|
|
import { store } from 'mastodon/store';
|
|
import { isProduction } from 'mastodon/utils/environment';
|
|
import { BodyScrollLock } from 'mastodon/features/ui/components/body_scroll_lock';
|
|
|
|
import { ScrollContext } from './scroll_container/scroll_context';
|
|
|
|
const title = isProduction() ? siteTitle : `${siteTitle} (Dev)`;
|
|
|
|
const hydrateAction = hydrateStore(initialState);
|
|
|
|
store.dispatch(hydrateAction);
|
|
if (initialState.meta.me) {
|
|
store.dispatch(fetchCustomEmojis());
|
|
}
|
|
|
|
export default class Mastodon extends PureComponent {
|
|
identity = createIdentityContext(initialState);
|
|
|
|
componentDidMount() {
|
|
if (this.identity.signedIn) {
|
|
this.disconnect = store.dispatch(connectUserStream());
|
|
}
|
|
}
|
|
|
|
componentWillUnmount () {
|
|
if (this.disconnect) {
|
|
this.disconnect();
|
|
this.disconnect = null;
|
|
}
|
|
}
|
|
|
|
render () {
|
|
return (
|
|
<IdentityContext.Provider value={this.identity}>
|
|
<IntlProvider>
|
|
<ReduxProvider store={store}>
|
|
<ErrorBoundary>
|
|
<Router>
|
|
<ScrollContext>
|
|
<Route path='/' component={UI} />
|
|
</ScrollContext>
|
|
<BodyScrollLock />
|
|
</Router>
|
|
|
|
<Helmet defaultTitle={title} titleTemplate={`%s - ${title}`} />
|
|
</ErrorBoundary>
|
|
</ReduxProvider>
|
|
</IntlProvider>
|
|
</IdentityContext.Provider>
|
|
);
|
|
}
|
|
|
|
}
|