]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/containers/mastodon.js
1 import React
from 'react';
2 import { Provider
} from 'react-redux';
3 import PropTypes
from 'prop-types';
4 import configureStore
from '../store/configureStore';
11 } from '../actions/timelines';
12 import { showOnboardingOnce
} from '../actions/onboarding';
13 import { updateNotifications
, refreshNotifications
} from '../actions/notifications';
14 import BrowserRouter
from 'react-router-dom/BrowserRouter';
15 import Route
from 'react-router-dom/Route';
16 import ScrollContext
from 'react-router-scroll/lib/ScrollBehaviorContext';
17 import UI
from '../features/ui';
18 import { hydrateStore
} from '../actions/store';
19 import createStream
from '../stream';
20 import { IntlProvider
, addLocaleData
} from 'react-intl';
21 import { getLocale
} from '../locales';
22 const { localeData
, messages
} = getLocale();
23 addLocaleData(localeData
);
25 const store
= configureStore();
26 const initialState
= JSON
.parse(document
.getElementById('initial-state').textContent
);
27 store
.dispatch(hydrateStore(initialState
));
29 class Mastodon
extends React
.PureComponent
{
32 const { locale
} = this.props
;
33 const streamingAPIBaseURL
= store
.getState().getIn(['meta', 'streaming_api_base_url']);
34 const accessToken
= store
.getState().getIn(['meta', 'access_token']);
36 const setupPolling
= () => {
37 this.polling
= setInterval(() => {
38 store
.dispatch(refreshHomeTimeline());
39 store
.dispatch(refreshNotifications());
43 const clearPolling
= () => {
44 clearInterval(this.polling
);
45 this.polling
= undefined;
48 this.subscription
= createStream(streamingAPIBaseURL
, accessToken
, 'user', {
52 store
.dispatch(connectTimeline('home'));
57 store
.dispatch(disconnectTimeline('home'));
63 store
.dispatch(updateTimeline('home', JSON
.parse(data
.payload
)));
66 store
.dispatch(deleteFromTimelines(data
.payload
));
69 store
.dispatch(updateNotifications(JSON
.parse(data
.payload
), messages
, locale
));
76 store
.dispatch(connectTimeline('home'));
77 store
.dispatch(refreshHomeTimeline());
78 store
.dispatch(refreshNotifications());
83 // Desktop notifications
84 if (typeof window
.Notification
!== 'undefined' && Notification
.permission
=== 'default') {
85 Notification
.requestPermission();
88 store
.dispatch(showOnboardingOnce());
91 componentWillUnmount () {
92 if (typeof this.subscription
!== 'undefined') {
93 this.subscription
.close();
94 this.subscription
= null;
97 if (typeof this.polling
!== 'undefined') {
98 clearInterval(this.polling
);
104 const { locale
} = this.props
;
107 <IntlProvider locale
={locale
} messages
={messages
}>
108 <Provider store
={store
}>
109 <BrowserRouter basename
='/web'>
111 <Route path
='/' component
={UI
} />
121 Mastodon
.propTypes
= {
122 locale: PropTypes
.string
.isRequired
,
125 export default Mastodon
;
This page took 0.092022 seconds and 4 git commands to generate.