Fix a bug logging the user out when calling certain sites

This has happened because the store was being updated before
it was rehydrated, and thus first saving an empty state, which
is thereafter being loaded when rehydrating the application state.
This commit is contained in:
JP1998 2019-04-16 23:20:44 +02:00
parent dc3b1a2cac
commit 75f7186ca7
2 changed files with 10 additions and 8 deletions

View File

@ -340,6 +340,7 @@ const default_applicationstate = {
};
var __store;
var applicationHydrated = false;
export function initializeStore(initialState = default_applicationstate) {
__store = createStore(
@ -348,7 +349,9 @@ export function initializeStore(initialState = default_applicationstate) {
composeWithDevTools(applyMiddleware(thunkMiddleware))
);
__store.subscribe(() => {
localStorage.setItem('reduxState', JSON.stringify(__store.getState()));
if(applicationHydrated) {
localStorage.setItem('reduxState', JSON.stringify(__store.getState()));
}
});
return __store;
}
@ -449,11 +452,12 @@ function rehydrateApplicationState() {
if(persistedState) {
__store.dispatch({
type : actiontypes_userinfo.REHYDRATE,
parameters : Object.assign({}, persistedState.userinfo, {})
parameters : Object.assign({}, persistedState.userinfo)
});
__store.dispatch({
type : actiontypes_tournamentinfo.REHYDRATE,
parameters : Object.assign({}, persistedState.tournamentinfo, {})
parameters : Object.assign({}, persistedState.tournamentinfo)
});
applicationHydrated = true;
}
}

View File

@ -25,7 +25,7 @@ import { createTournament } from '../js/api';
import '../static/everypage.css';
class PrivateCreatePage extends React.Component {
class CreatePage extends React.Component {
render() {
const { isSignedIn } = this.props;
@ -66,11 +66,9 @@ function mapStateToCreatePageProperties(state) {
return { isSignedIn };
}
const CreatePage = connect(
export default connect(
mapStateToCreatePageProperties
)(PrivateCreatePage);
export default CreatePage;
)(CreatePage);
function CreateTournamentCard() {
return (