kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Reload the page conditionally
rodzic
b4cab46553
commit
94da1f6722
|
@ -116,13 +116,28 @@ const reducer = (state, action) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function auth(oldState = initialState, action) {
|
const maybeReload = (oldState, state, action) => {
|
||||||
const state = reducer(oldState, action);
|
const conds = [
|
||||||
localStorage.setItem('soapbox:auth', JSON.stringify(state.toJS()));
|
action.type === SWITCH_ACCOUNT,
|
||||||
|
action.type === VERIFY_CREDENTIALS_FAIL && state.get('me') !== oldState.get('me'),
|
||||||
|
];
|
||||||
|
|
||||||
if (action.type === SWITCH_ACCOUNT) {
|
// Reload if any of these conditions are true
|
||||||
|
const shouldReload = conds.some(cond => cond);
|
||||||
|
|
||||||
|
if (shouldReload) {
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function auth(oldState = initialState, action) {
|
||||||
|
const state = reducer(oldState, action);
|
||||||
|
|
||||||
|
// Persist the state in localStorage
|
||||||
|
localStorage.setItem('soapbox:auth', JSON.stringify(state.toJS()));
|
||||||
|
|
||||||
|
// Reload the page under some conditions
|
||||||
|
maybeReload(oldState, state, action);
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
};
|
};
|
||||||
|
|
Ładowanie…
Reference in New Issue