From c99e43d6c625ed7d0bb4f1d25026512460445bef Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 11 Sep 2024 21:56:20 -0500 Subject: [PATCH] Protect against other exit methods, protect against multiple fetches --- .../dialogs/nuxs/TenMillion/index.tsx | 10 +++++++--- src/components/dialogs/nuxs/index.tsx | 19 +++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/components/dialogs/nuxs/TenMillion/index.tsx b/src/components/dialogs/nuxs/TenMillion/index.tsx index f5c8435d..c7775514 100644 --- a/src/components/dialogs/nuxs/TenMillion/index.tsx +++ b/src/components/dialogs/nuxs/TenMillion/index.tsx @@ -87,6 +87,7 @@ export function TenMillion() { const agent = useAgent() const nuxDialogs = useNuxDialogContext() const [userNumber, setUserNumber] = React.useState(0) + const fetching = React.useRef(false) React.useEffect(() => { async function fetchUserNumber() { @@ -119,9 +120,12 @@ export function TenMillion() { } } - networkRetry(3, fetchUserNumber).catch(() => { - nuxDialogs.dismissActiveNux() - }) + if (!fetching.current) { + fetching.current = true + networkRetry(3, fetchUserNumber).catch(() => { + nuxDialogs.dismissActiveNux() + }) + } }, [ agent.sessionManager.pdsUrl, agent.session?.accessJwt, diff --git a/src/components/dialogs/nuxs/index.tsx b/src/components/dialogs/nuxs/index.tsx index c02af59f..f60c9e8d 100644 --- a/src/components/dialogs/nuxs/index.tsx +++ b/src/components/dialogs/nuxs/index.tsx @@ -49,14 +49,7 @@ function Inner() { const dismissActiveNux = React.useCallback(() => { if (!activeNux) return setActiveNux(undefined) - const nux = nuxs?.find(nux => nux.id === activeNux) - upsertNux({ - id: activeNux, - completed: true, - data: nux?.data, - expiresAt: nux?.expiresAt, - }) - }, [activeNux, setActiveNux, upsertNux, nuxs]) + }, [activeNux, setActiveNux]) if (IS_DEV && typeof window !== 'undefined') { // @ts-ignore @@ -77,12 +70,18 @@ function Inner() { if (nux && nux.completed) continue setActiveNux(id) - // snooze immediately upon enabling + // immediately snooze (in memory) snoozeNuxDialog() + // immediately update remote data + upsertNux({ + id, + completed: true, + data: undefined, + }) break } - }, [nuxs, snoozed, snoozeNuxDialog]) + }, [nuxs, snoozed, snoozeNuxDialog, upsertNux]) const ctx = React.useMemo(() => { return {