Skip to content

Commit

Permalink
Merge pull request #4171 from tloncorp/lb/invite-auth-nav
Browse files Browse the repository at this point in the history
native: fix authed invite link click
  • Loading branch information
latter-bolden authored Nov 12, 2024
2 parents 5a3c627 + 963a982 commit f9ebc59
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions apps/tlon-mobile/src/hooks/useDeepLinkListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { NavigationProp, useNavigation } from '@react-navigation/native';
import { useBranch, useSignupParams } from '@tloncorp/app/contexts/branch';
import { useShip } from '@tloncorp/app/contexts/ship';
import { RootStackParamList } from '@tloncorp/app/navigation/types';
import { useTypedReset } from '@tloncorp/app/navigation/utils';
import { createDevLogger } from '@tloncorp/shared';
import * as store from '@tloncorp/shared/store';
import { useEffect, useRef } from 'react';

const logger = createDevLogger('deeplinkHandler', true);
Expand All @@ -14,6 +14,7 @@ export const useDeepLinkListener = () => {
const { ship } = useShip();
const signupParams = useSignupParams();
const { clearLure, lure } = useBranch();
const reset = useTypedReset();

useEffect(() => {
if (ship && lure && !isHandlingLinkRef.current) {
Expand All @@ -27,22 +28,16 @@ export const useDeepLinkListener = () => {
} else {
// otherwise, treat it as a deeplink and navigate to the group
if (lure.invitedGroupId) {
const [group] = await store.syncGroupPreviews([
lure.invitedGroupId,
logger.log(
`handling deep link to invited group`,
lure.invitedGroupId
);
reset([
{
name: 'ChatList',
params: { previewGroupId: lure.invitedGroupId },
},
]);
if (group) {
navigation.reset({
index: 1,
routes: [
{ name: 'ChatList', params: { previewGroup: group } },
],
});
} else {
logger.error(
'Failed to navigate to group deeplink',
lure.invitedGroupId
);
}
}
}
} catch (e) {
Expand All @@ -53,5 +48,5 @@ export const useDeepLinkListener = () => {
}
})();
}
}, [ship, signupParams, clearLure, lure, navigation]);
}, [ship, signupParams, clearLure, lure, navigation, reset]);
};

0 comments on commit f9ebc59

Please sign in to comment.