Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3381713
D12423.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D12423.diff
View Options
diff --git a/lib/hooks/invite-links.js b/lib/hooks/invite-links.js
--- a/lib/hooks/invite-links.js
+++ b/lib/hooks/invite-links.js
@@ -29,7 +29,6 @@
} from '../types/link-types.js';
import type { LoadingStatus } from '../types/loading-types.js';
import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
-import type { ThreadJoinPayload } from '../types/thread-types.js';
import { useDispatchActionPromise } from '../utils/redux-promise-utils.js';
import { useDispatch, useSelector } from '../utils/redux-utils.js';
@@ -199,7 +198,7 @@
const isKeyserverURLValid = useIsKeyserverURLValid(keyserverURL);
const [ongoingJoinData, setOngoingJoinData] = React.useState<?{
- +resolve: ThreadJoinPayload => mixed,
+ +resolve: () => mixed,
+reject: () => mixed,
+communityID: string,
}>(null);
@@ -213,8 +212,8 @@
};
}, []);
- const createJoinCommunityAction = React.useCallback(() => {
- return new Promise<ThreadJoinPayload>((resolve, reject) => {
+ const createJoinPromise = React.useCallback(() => {
+ return new Promise<void>((resolve, reject) => {
if (
!keyserverID ||
!communityID ||
@@ -235,9 +234,9 @@
});
}, permissionsAndAuthRelatedRequestTimeout);
timeoutRef.current = timeoutID;
- const resolveAndClearTimeout = (result: ThreadJoinPayload) => {
+ const resolveAndClearTimeout = () => {
clearTimeout(timeoutID);
- resolve(result);
+ resolve();
};
const rejectAndClearTimeout = () => {
clearTimeout(timeoutID);
@@ -281,6 +280,7 @@
setLinkStatus,
]);
+ const dispatchActionPromise = useDispatchActionPromise();
const [joined, setJoined] = React.useState(false);
React.useEffect(() => {
void (async () => {
@@ -289,22 +289,24 @@
}
const threadID = ongoingJoinData.communityID;
const query = calendarQuery();
+ const joinThreadPromise = callJoinThread({
+ threadID,
+ calendarQuery: {
+ startDate: query.startDate,
+ endDate: query.endDate,
+ filters: [
+ ...query.filters,
+ { type: 'threads', threadIDs: [threadID] },
+ ],
+ },
+ inviteLinkSecret: inviteSecret,
+ });
+ void dispatchActionPromise(joinThreadActionTypes, joinThreadPromise);
try {
- const result = await callJoinThread({
- threadID,
- calendarQuery: {
- startDate: query.startDate,
- endDate: query.endDate,
- filters: [
- ...query.filters,
- { type: 'threads', threadIDs: [threadID] },
- ],
- },
- inviteLinkSecret: inviteSecret,
- });
+ await joinThreadPromise;
setJoined(true);
- ongoingJoinData.resolve(result);
+ ongoingJoinData.resolve();
} catch (e) {
setLinkStatus(status => (status === 'valid' ? 'invalid' : status));
ongoingJoinData.reject();
@@ -315,11 +317,10 @@
}, [
calendarQuery,
callJoinThread,
- communityID,
+ dispatchActionPromise,
inviteSecret,
isAuthenticated,
ongoingJoinData,
- closeModal,
setLinkStatus,
]);
@@ -342,22 +343,14 @@
verificationResponse.community?.id,
]);
- const dispatchActionPromise = useDispatchActionPromise();
- const join = React.useCallback(() => {
- void dispatchActionPromise(
- joinThreadActionTypes,
- createJoinCommunityAction(),
- );
- }, [createJoinCommunityAction, dispatchActionPromise]);
-
const joinLoadingStatus = useSelector(joinThreadLoadingStatusSelector);
return React.useMemo(
() => ({
- join,
+ join: createJoinPromise,
joinLoadingStatus,
}),
- [join, joinLoadingStatus],
+ [createJoinPromise, joinLoadingStatus],
);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 5:59 AM (21 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2596125
Default Alt Text
D12423.diff (3 KB)
Attached To
Mode
D12423: [lib] Modify the approach to handling invite link acceptance
Attached
Detach File
Event Timeline
Log In to Comment