masto-fe/app/javascript/themes/glitch/containers/mastodon.js

71 lines
2.2 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { Provider } from 'react-redux';
import PropTypes from 'prop-types';
2017-11-18 03:11:18 +00:00
import configureStore from 'themes/glitch/store/configureStore';
import { showOnboardingOnce } from 'themes/glitch/actions/onboarding';
import { BrowserRouter, Route } from 'react-router-dom';
import { ScrollContext } from 'react-router-scroll-4';
2017-11-18 03:11:18 +00:00
import UI from 'themes/glitch/features/ui';
import { hydrateStore } from 'themes/glitch/actions/store';
import { connectUserStream } from 'themes/glitch/actions/streaming';
import { IntlProvider, addLocaleData } from 'react-intl';
2017-11-18 03:11:18 +00:00
import { getLocale } from 'mastodon/locales';
import initialState from 'themes/glitch/util/initial_state';
const { localeData, messages } = getLocale();
addLocaleData(localeData);
export const store = configureStore();
const hydrateAction = hydrateStore(initialState);
store.dispatch(hydrateAction);
2017-01-09 11:37:15 +00:00
export default class Mastodon extends React.PureComponent {
static propTypes = {
locale: PropTypes.string.isRequired,
};
componentDidMount() {
this.disconnect = store.dispatch(connectUserStream());
2016-11-20 18:39:18 +00:00
// Desktop notifications
// Ask after 1 minute
if (typeof window.Notification !== 'undefined' && Notification.permission === 'default') {
window.setTimeout(() => Notification.requestPermission(), 60 * 1000);
2016-11-20 18:39:18 +00:00
}
// Protocol handler
// Ask after 5 minutes
if (typeof navigator.registerProtocolHandler !== 'undefined') {
const handlerUrl = window.location.protocol + '//' + window.location.host + '/intent?uri=%s';
window.setTimeout(() => navigator.registerProtocolHandler('web+mastodon', handlerUrl, 'Mastodon'), 5 * 60 * 1000);
}
store.dispatch(showOnboardingOnce());
}
2016-10-07 14:00:11 +00:00
componentWillUnmount () {
if (this.disconnect) {
this.disconnect();
this.disconnect = null;
}
}
2016-10-07 14:00:11 +00:00
render () {
const { locale } = this.props;
return (
<IntlProvider locale={locale} messages={messages}>
<Provider store={store}>
<BrowserRouter basename='/web'>
<ScrollContext>
<Route path='/' component={UI} />
</ScrollContext>
</BrowserRouter>
</Provider>
</IntlProvider>
);
}
}