diff --git a/src/components/dialogs/EmailDialog/data/useIsEmailVerified.ts b/src/components/dialogs/EmailDialog/data/useIsEmailVerified.ts index 5355786d3b..e3066d4604 100644 --- a/src/components/dialogs/EmailDialog/data/useIsEmailVerified.ts +++ b/src/components/dialogs/EmailDialog/data/useIsEmailVerified.ts @@ -1,4 +1,4 @@ -import {useCallback, useRef} from 'react' +import {useCallback, useState} from 'react' import {useQuery, useQueryClient} from '@tanstack/react-query' import {useAgent} from '#/state/session' @@ -21,28 +21,28 @@ export function useIsEmailVerified({ onVerify?: () => void } = {}) { const agent = useAgent() - const prevIsEmailVerified = useRef(!!agent.session?.emailConfirmed) + const [prevIsEmailVerified, setPrevEmailIsVerified] = useState( + !!agent.session?.emailConfirmed, + ) const query = useQuery({ enabled: !!agent.session, initialData: {isEmailVerified: !!agent.session?.emailConfirmed}, refetchOnWindowFocus: true, queryKey: isEmailVerifiedQueryKey, queryFn: async () => { - const {data} = await agent.com.atproto.server.getSession() + // will also trigger updates to `#/state/session` data + const {data} = await agent.resumeSession(agent.session!) return { isEmailVerified: !!data.emailConfirmed, } }, }) - // TODO double check racing? - if (query.data.isEmailVerified && !prevIsEmailVerified.current) { - console.log('fire') - prevIsEmailVerified.current = true + if (query.data.isEmailVerified && !prevIsEmailVerified) { + setPrevEmailIsVerified(true) onVerify?.() - } else if (prevIsEmailVerified.current && !query.data.isEmailVerified) { - console.log('reset') - prevIsEmailVerified.current = false + } else if (!query.data.isEmailVerified && prevIsEmailVerified) { + setPrevEmailIsVerified(false) } return query.data diff --git a/src/components/dialogs/EmailDialog/data/useRefreshSession.ts b/src/components/dialogs/EmailDialog/data/useRefreshSession.ts deleted file mode 100644 index 72fcdb577e..0000000000 --- a/src/components/dialogs/EmailDialog/data/useRefreshSession.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {useCallback} from 'react' - -import {useAgent} from '#/state/session' - -export function useRefreshSession() { - const agent = useAgent() - - return useCallback(() => { - return agent.resumeSession(agent.session!).catch(() => {}) - }, [agent]) -} diff --git a/src/components/dialogs/EmailDialog/index.tsx b/src/components/dialogs/EmailDialog/index.tsx index 3787bf9491..a59d45a0bb 100644 --- a/src/components/dialogs/EmailDialog/index.tsx +++ b/src/components/dialogs/EmailDialog/index.tsx @@ -7,11 +7,7 @@ import { type StatefulControl, useStatefulDialogControl, } from '#/components/dialogs/Context' -import {useRefreshSession} from '#/components/dialogs/EmailDialog/data/useRefreshSession' import {Manage2FA} from '#/components/dialogs/EmailDialog/screens/Manage2FA' -/* - * Steps - */ import {Update} from '#/components/dialogs/EmailDialog/screens/Update' import {VerificationReminder} from '#/components/dialogs/EmailDialog/screens/VerificationReminder' import {Verify} from '#/components/dialogs/EmailDialog/screens/Verify' @@ -27,15 +23,7 @@ export function useEmailDialogControl() { export function EmailDialog({control}: {control: StatefulControl}) { const {_} = useLingui() - const refreshSession = useRefreshSession() - const onClose = useCallback(() => { - /** - * If link in any verification email is clicked, it will open a new tab. - * When the user returns to this tab, we'll refresh their account state - * when the dialog closes. - */ - refreshSession() - }, [refreshSession]) + const onClose = useCallback(() => {}, []) return ( diff --git a/src/components/dialogs/EmailDialog/screens/Verify.tsx b/src/components/dialogs/EmailDialog/screens/Verify.tsx index adca558ad0..2ded351a01 100644 --- a/src/components/dialogs/EmailDialog/screens/Verify.tsx +++ b/src/components/dialogs/EmailDialog/screens/Verify.tsx @@ -163,7 +163,8 @@ export function Verify({config}: ScreenProps) { - {' '} + + {' '} Email verification complete! @@ -188,7 +189,8 @@ export function Verify({config}: ScreenProps) { <> - {' '} + + {' '} Email sent! ) : (