|
|
|
|
|
import 'css.escape'; |
|
|
import React from 'react'; |
|
|
import ReactDOM from 'react-dom'; |
|
|
import { ApolloProvider } from 'react-apollo'; |
|
|
import { Provider } from 'react-redux'; |
|
|
import { Router } from 'react-router'; |
|
|
import queryString from 'query-string'; |
|
|
import Loadable from 'react-loadable'; |
|
|
import * as OfflinePluginRuntime from 'offline-plugin/runtime'; |
|
|
import { HelmetProvider } from 'react-helmet-async'; |
|
|
import webPushManager from 'src/helpers/web-push-manager'; |
|
|
import { history } from 'src/helpers/history'; |
|
|
import { client } from 'shared/graphql'; |
|
|
import { initStore } from 'src/store'; |
|
|
import { wsLink } from 'shared/graphql'; |
|
|
import RedirectHandler from 'src/components/redirectHandler'; |
|
|
const params = queryString.parse(history.location.search); |
|
|
|
|
|
|
|
|
|
|
|
const threadParam = params.thread || params.t; |
|
|
if (threadParam) { |
|
|
if (params.m) { |
|
|
history.replace(`/thread/${threadParam}?m=${params.m}`); |
|
|
} else { |
|
|
history.replace(`/thread/${threadParam}`); |
|
|
} |
|
|
} |
|
|
|
|
|
const store = initStore(window.__SERVER_STATE__ || {}); |
|
|
|
|
|
const App = () => { |
|
|
return ( |
|
|
<Provider store={store}> |
|
|
<HelmetProvider> |
|
|
<ApolloProvider client={client}> |
|
|
<Router history={history}> |
|
|
<RedirectHandler |
|
|
maintenanceMode={ |
|
|
process.env.REACT_APP_MAINTENANCE_MODE === 'enabled' |
|
|
} |
|
|
/> |
|
|
</Router> |
|
|
</ApolloProvider> |
|
|
</HelmetProvider> |
|
|
</Provider> |
|
|
); |
|
|
}; |
|
|
|
|
|
const renderMethod = window.__SERVER_STATE__ |
|
|
? |
|
|
ReactDOM.hydrate |
|
|
: ReactDOM.render; |
|
|
|
|
|
function render() { |
|
|
return renderMethod( |
|
|
<App />, |
|
|
|
|
|
document.querySelector('#root') |
|
|
); |
|
|
} |
|
|
|
|
|
Loadable.preloadReady() |
|
|
.then(render) |
|
|
.catch(err => { |
|
|
console.error(err); |
|
|
}); |
|
|
|
|
|
OfflinePluginRuntime.install({ |
|
|
|
|
|
onUpdateReady: () => OfflinePluginRuntime.applyUpdate(), |
|
|
}); |
|
|
|
|
|
if ('serviceWorker' in navigator && 'PushManager' in window) { |
|
|
|
|
|
navigator.serviceWorker.ready.then(registration => { |
|
|
webPushManager.set(registration.pushManager); |
|
|
}); |
|
|
} |
|
|
|
|
|
wsLink.subscriptionClient.on('disconnected', () => |
|
|
store.dispatch({ type: 'WEBSOCKET_CONNECTION', value: 'disconnected' }) |
|
|
); |
|
|
wsLink.subscriptionClient.on('connected', () => |
|
|
store.dispatch({ type: 'WEBSOCKET_CONNECTION', value: 'connected' }) |
|
|
); |
|
|
wsLink.subscriptionClient.on('reconnected', () => |
|
|
store.dispatch({ type: 'WEBSOCKET_CONNECTION', value: 'reconnected' }) |
|
|
); |
|
|
|