pixelplanet/src/popup.js
HF e9952134a5 refactor socket events
send captcha solution via websocket
2022-10-03 15:07:34 +02:00

40 lines
946 B
JavaScript

/*
* Main Script for windows (pop-ups and stuff)
*/
import { persistStore } from 'redux-persist';
import { parentExists } from './core/utils';
import store from './store/storePopUp';
import {
urlChange,
} from './store/actions';
import {
fetchMe,
} from './store/actions/thunks';
import SocketClient from './socket/SocketClient';
import renderAppPopUp from './components/AppPopUp';
persistStore(store, {}, () => {
window.addEventListener('message', store.dispatch);
store.dispatch({ type: 'HYDRATED' });
window.addEventListener('popstate', () => {
store.dispatch(urlChange());
});
if (!parentExists()) {
store.dispatch(fetchMe());
SocketClient.initialize(store);
}
});
(function load() {
const onLoad = () => {
renderAppPopUp(document.getElementById('app'), store);
document.removeEventListener('DOMContentLoaded', onLoad);
};
document.addEventListener('DOMContentLoaded', onLoad, false);
}());