diff --git a/lib/reducers/invite-links-reducer.js b/lib/reducers/invite-links-reducer.js --- a/lib/reducers/invite-links-reducer.js +++ b/lib/reducers/invite-links-reducer.js @@ -5,8 +5,13 @@ disableInviteLinkLinkActionTypes, fetchPrimaryInviteLinkActionTypes, } from '../actions/link-actions.js'; +import { + deleteAccountActionTypes, + logOutActionTypes, +} from '../actions/user-actions.js'; import type { InviteLinksStore } from '../types/link-types.js'; import type { BaseAction } from '../types/redux-types.js'; +import { setNewSessionActionType } from '../utils/action-utils.js'; function reduceInviteLinks( state: InviteLinksStore, @@ -53,6 +58,15 @@ [communityID]: communityLinks, }, }; + } else if ( + action.type === logOutActionTypes.success || + action.type === deleteAccountActionTypes.success || + (action.type === setNewSessionActionType && + action.payload.sessionChange.cookieInvalidated) + ) { + return { + links: {}, + }; } return state; } diff --git a/web/app.react.js b/web/app.react.js --- a/web/app.react.js +++ b/web/app.react.js @@ -41,6 +41,7 @@ import electron from './electron.js'; import InputStateContainer from './input/input-state-container.react.js'; import InviteLinkHandler from './invite-links/invite-link-handler.react.js'; +import InviteLinksRefresher from './invite-links/invite-links-refresher.react.js'; import LoadingIndicator from './loading-indicator.react.js'; import { MenuProvider } from './menu-provider.react.js'; import UpdateModalHandler from './modals/update-modal.react.js'; @@ -192,6 +193,7 @@ + {content} diff --git a/web/invite-links/invite-links-refresher.react.js b/web/invite-links/invite-links-refresher.react.js new file mode 100644 --- /dev/null +++ b/web/invite-links/invite-links-refresher.react.js @@ -0,0 +1,36 @@ +// @flow + +import * as React from 'react'; + +import { + fetchPrimaryInviteLinkActionTypes, + fetchPrimaryInviteLinks, +} from 'lib/actions/link-actions.js'; +import { isLoggedIn } from 'lib/selectors/user-selectors.js'; +import { + useDispatchActionPromise, + useServerCall, +} from 'lib/utils/action-utils.js'; + +import { useSelector } from '../redux/redux-utils.js'; + +function InviteLinksRefresher(): React.Node { + const isActive = useSelector(state => state.windowActive); + const loggedIn = useSelector(isLoggedIn); + const callFetchPrimaryLinks = useServerCall(fetchPrimaryInviteLinks); + const dispatchActionPromise = useDispatchActionPromise(); + + React.useEffect(() => { + if (!isActive || !loggedIn) { + return; + } + dispatchActionPromise( + fetchPrimaryInviteLinkActionTypes, + callFetchPrimaryLinks(), + ); + }, [callFetchPrimaryLinks, dispatchActionPromise, isActive, loggedIn]); + + return null; +} + +export default InviteLinksRefresher;