diff --git a/web/app.react.js b/web/app.react.js --- a/web/app.react.js +++ b/web/app.react.js @@ -40,6 +40,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'; @@ -179,6 +180,7 @@ + {content} {this.props.modals} 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,34 @@ +// @flow + +import * as React from 'react'; + +import { + fetchPrimaryInviteLinkActionTypes, + fetchPrimaryInviteLinks, +} from 'lib/actions/link-actions.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 callFetchPrimaryLinks = useServerCall(fetchPrimaryInviteLinks); + const dispatchActionPromise = useDispatchActionPromise(); + + React.useEffect(() => { + if (!isActive) { + return; + } + dispatchActionPromise( + fetchPrimaryInviteLinkActionTypes, + callFetchPrimaryLinks(), + ); + }, [callFetchPrimaryLinks, dispatchActionPromise, isActive]); + + return null; +} + +export default InviteLinksRefresher;