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.
103 lines
3.0 KiB
103 lines
3.0 KiB
8 years ago
|
import PropTypes from 'prop-types';
|
||
2 years ago
|
import React from 'react';
|
||
|
import { Helmet } from 'react-helmet';
|
||
|
import { IntlProvider, addLocaleData } from 'react-intl';
|
||
|
import { Provider as ReduxProvider } from 'react-redux';
|
||
7 years ago
|
import { BrowserRouter, Route } from 'react-router-dom';
|
||
7 years ago
|
import { ScrollContext } from 'react-router-scroll-4';
|
||
2 years ago
|
import configureStore from 'flavours/glitch/store/configureStore';
|
||
7 years ago
|
import UI from 'flavours/glitch/features/ui';
|
||
7 years ago
|
import { fetchCustomEmojis } from 'flavours/glitch/actions/custom_emojis';
|
||
7 years ago
|
import { hydrateStore } from 'flavours/glitch/actions/store';
|
||
3 years ago
|
import { checkDeprecatedLocalSettings } from 'flavours/glitch/actions/local_settings';
|
||
2 years ago
|
import { connectUserStream } from 'flavours/glitch/actions/streaming';
|
||
6 years ago
|
import ErrorBoundary from 'flavours/glitch/components/error_boundary';
|
||
2 years ago
|
import initialState, { title as siteTitle } from 'flavours/glitch/initial_state';
|
||
|
import { getLocale } from 'locales';
|
||
7 years ago
|
|
||
8 years ago
|
const { localeData, messages } = getLocale();
|
||
|
addLocaleData(localeData);
|
||
8 years ago
|
|
||
2 years ago
|
const title = process.env.NODE_ENV === 'production' ? siteTitle : `${siteTitle} (Dev)`;
|
||
|
|
||
7 years ago
|
export const store = configureStore();
|
||
7 years ago
|
const hydrateAction = hydrateStore(initialState);
|
||
7 years ago
|
store.dispatch(hydrateAction);
|
||
8 years ago
|
|
||
3 years ago
|
// check for deprecated local settings
|
||
|
store.dispatch(checkDeprecatedLocalSettings());
|
||
|
|
||
2 years ago
|
if (initialState.meta.me) {
|
||
|
store.dispatch(fetchCustomEmojis());
|
||
|
}
|
||
7 years ago
|
|
||
3 years ago
|
const createIdentityContext = state => ({
|
||
|
signedIn: !!state.meta.me,
|
||
|
accountId: state.meta.me,
|
||
2 years ago
|
disabledAccountId: state.meta.disabled_account_id,
|
||
3 years ago
|
accessToken: state.meta.access_token,
|
||
2 years ago
|
permissions: state.role ? state.role.permissions : 0,
|
||
3 years ago
|
});
|
||
|
|
||
8 years ago
|
export default class Mastodon extends React.PureComponent {
|
||
|
|
||
|
static propTypes = {
|
||
|
locale: PropTypes.string.isRequired,
|
||
|
};
|
||
8 years ago
|
|
||
3 years ago
|
static childContextTypes = {
|
||
|
identity: PropTypes.shape({
|
||
|
signedIn: PropTypes.bool.isRequired,
|
||
|
accountId: PropTypes.string,
|
||
2 years ago
|
disabledAccountId: PropTypes.string,
|
||
3 years ago
|
accessToken: PropTypes.string,
|
||
|
}).isRequired,
|
||
|
};
|
||
|
|
||
|
identity = createIdentityContext(initialState);
|
||
|
|
||
|
getChildContext() {
|
||
|
return {
|
||
|
identity: this.identity,
|
||
|
};
|
||
|
}
|
||
|
|
||
8 years ago
|
componentDidMount() {
|
||
3 years ago
|
if (this.identity.signedIn) {
|
||
|
this.disconnect = store.dispatch(connectUserStream());
|
||
|
}
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
componentWillUnmount () {
|
||
7 years ago
|
if (this.disconnect) {
|
||
|
this.disconnect();
|
||
|
this.disconnect = null;
|
||
8 years ago
|
}
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
5 years ago
|
shouldUpdateScroll (_, { location }) {
|
||
3 years ago
|
return !(location.state?.mastodonModalKey);
|
||
5 years ago
|
}
|
||
|
|
||
8 years ago
|
render () {
|
||
8 years ago
|
const { locale } = this.props;
|
||
|
|
||
8 years ago
|
return (
|
||
8 years ago
|
<IntlProvider locale={locale} messages={messages}>
|
||
2 years ago
|
<ReduxProvider store={store}>
|
||
6 years ago
|
<ErrorBoundary>
|
||
2 years ago
|
<BrowserRouter>
|
||
5 years ago
|
<ScrollContext shouldUpdateScroll={this.shouldUpdateScroll}>
|
||
6 years ago
|
<Route path='/' component={UI} />
|
||
|
</ScrollContext>
|
||
|
</BrowserRouter>
|
||
2 years ago
|
|
||
|
<Helmet defaultTitle={title} titleTemplate={`%s - ${title}`} />
|
||
6 years ago
|
</ErrorBoundary>
|
||
2 years ago
|
</ReduxProvider>
|
||
8 years ago
|
</IntlProvider>
|
||
8 years ago
|
);
|
||
|
}
|
||
|
|
||
8 years ago
|
}
|