Skip to content

Commit

Permalink
[web] Refresh invite links
Browse files Browse the repository at this point in the history
Summary:
Every time a window becomes active, fetch invite links so that we can display the most recent version without requesting too often. Ultimately, we would like to have a mechanism where every invite link change results in updates being sent to interested clients.

Depends on D8239

Test Plan:
Check if actions are dispatched when the window becomes active.
Modify website responder so that an empty invite links store is returned. Check if the links are updated after successful result is returned from the server when a window becomes active.

Reviewers: bartek, kamil, inka

Reviewed By: kamil

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D8246
  • Loading branch information
palys-swm committed Jun 26, 2023
1 parent a28409f commit bd5f5b2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/reducers/invite-links-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import {
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,
Expand Down Expand Up @@ -53,6 +58,15 @@ function reduceInviteLinks(
[communityID]: communityLinks,
},
};
} else if (
action.type === logOutActionTypes.success ||
action.type === deleteAccountActionTypes.success ||
(action.type === setNewSessionActionType &&
action.payload.sessionChange.cookieInvalidated)
) {
return {
links: {},
};
}
return state;
}
Expand Down
2 changes: 2 additions & 0 deletions web/app.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { initOpaque } from './crypto/opaque-utils.js';
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';
Expand Down Expand Up @@ -192,6 +193,7 @@ class App extends React.PureComponent<Props> {
<PolicyAcknowledgmentHandler />
<PushNotificationsHandler />
<InviteLinkHandler />
<InviteLinksRefresher />
{content}
</WagmiENSCacheProvider>
</WagmiConfig>
Expand Down
36 changes: 36 additions & 0 deletions web/invite-links/invite-links-refresher.react.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit bd5f5b2

Please sign in to comment.