Protect against other exit methods, protect against multiple fetches
parent
45c8d89d92
commit
c99e43d6c6
|
@ -87,6 +87,7 @@ export function TenMillion() {
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
const nuxDialogs = useNuxDialogContext()
|
const nuxDialogs = useNuxDialogContext()
|
||||||
const [userNumber, setUserNumber] = React.useState<number>(0)
|
const [userNumber, setUserNumber] = React.useState<number>(0)
|
||||||
|
const fetching = React.useRef(false)
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
async function fetchUserNumber() {
|
async function fetchUserNumber() {
|
||||||
|
@ -119,9 +120,12 @@ export function TenMillion() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fetching.current) {
|
||||||
|
fetching.current = true
|
||||||
networkRetry(3, fetchUserNumber).catch(() => {
|
networkRetry(3, fetchUserNumber).catch(() => {
|
||||||
nuxDialogs.dismissActiveNux()
|
nuxDialogs.dismissActiveNux()
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}, [
|
}, [
|
||||||
agent.sessionManager.pdsUrl,
|
agent.sessionManager.pdsUrl,
|
||||||
agent.session?.accessJwt,
|
agent.session?.accessJwt,
|
||||||
|
|
|
@ -49,14 +49,7 @@ function Inner() {
|
||||||
const dismissActiveNux = React.useCallback(() => {
|
const dismissActiveNux = React.useCallback(() => {
|
||||||
if (!activeNux) return
|
if (!activeNux) return
|
||||||
setActiveNux(undefined)
|
setActiveNux(undefined)
|
||||||
const nux = nuxs?.find(nux => nux.id === activeNux)
|
}, [activeNux, setActiveNux])
|
||||||
upsertNux({
|
|
||||||
id: activeNux,
|
|
||||||
completed: true,
|
|
||||||
data: nux?.data,
|
|
||||||
expiresAt: nux?.expiresAt,
|
|
||||||
})
|
|
||||||
}, [activeNux, setActiveNux, upsertNux, nuxs])
|
|
||||||
|
|
||||||
if (IS_DEV && typeof window !== 'undefined') {
|
if (IS_DEV && typeof window !== 'undefined') {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -77,12 +70,18 @@ function Inner() {
|
||||||
if (nux && nux.completed) continue
|
if (nux && nux.completed) continue
|
||||||
|
|
||||||
setActiveNux(id)
|
setActiveNux(id)
|
||||||
// snooze immediately upon enabling
|
// immediately snooze (in memory)
|
||||||
snoozeNuxDialog()
|
snoozeNuxDialog()
|
||||||
|
// immediately update remote data
|
||||||
|
upsertNux({
|
||||||
|
id,
|
||||||
|
completed: true,
|
||||||
|
data: undefined,
|
||||||
|
})
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}, [nuxs, snoozed, snoozeNuxDialog])
|
}, [nuxs, snoozed, snoozeNuxDialog, upsertNux])
|
||||||
|
|
||||||
const ctx = React.useMemo(() => {
|
const ctx = React.useMemo(() => {
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue