Fallback snoozing
parent
36ac551347
commit
003f9e06d4
|
@ -1,6 +1,7 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import {useGate} from '#/lib/statsig/statsig'
|
import {useGate} from '#/lib/statsig/statsig'
|
||||||
|
import {logger} from '#/logger'
|
||||||
import {
|
import {
|
||||||
Nux,
|
Nux,
|
||||||
useNuxs,
|
useNuxs,
|
||||||
|
@ -17,6 +18,16 @@ type Context = {
|
||||||
dismissActiveNux: () => void
|
dismissActiveNux: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we fail to complete a NUX here, it may show again on next reload,
|
||||||
|
* or if prefs state updates. If `true`, this fallback ensures that the last
|
||||||
|
* shown NUX won't show again, at least for this session.
|
||||||
|
*
|
||||||
|
* This is temporary, and only needed for the 10Milly dialog rn, since we
|
||||||
|
* aren't snoozing that one in device storage.
|
||||||
|
*/
|
||||||
|
let __isSnoozedFallback = false
|
||||||
|
|
||||||
const queuedNuxs: {
|
const queuedNuxs: {
|
||||||
id: Nux
|
id: Nux
|
||||||
enabled(props: {gate: ReturnType<typeof useGate>}): boolean
|
enabled(props: {gate: ReturnType<typeof useGate>}): boolean
|
||||||
|
@ -56,7 +67,7 @@ function Inner() {
|
||||||
return isSnoozed()
|
return isSnoozed()
|
||||||
})
|
})
|
||||||
const [activeNux, setActiveNux] = React.useState<Nux | undefined>()
|
const [activeNux, setActiveNux] = React.useState<Nux | undefined>()
|
||||||
const {mutate: upsertNux} = useUpsertNuxMutation()
|
const {mutateAsync: upsertNux} = useUpsertNuxMutation()
|
||||||
const {mutate: removeNuxs} = useRemoveNuxsMutation()
|
const {mutate: removeNuxs} = useRemoveNuxsMutation()
|
||||||
|
|
||||||
const snoozeNuxDialog = React.useCallback(() => {
|
const snoozeNuxDialog = React.useCallback(() => {
|
||||||
|
@ -79,6 +90,7 @@ function Inner() {
|
||||||
}
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
if (__isSnoozedFallback) return
|
||||||
if (snoozed) return
|
if (snoozed) return
|
||||||
if (!nuxs) return
|
if (!nuxs) return
|
||||||
|
|
||||||
|
@ -99,7 +111,7 @@ function Inner() {
|
||||||
* other NUX dialogs configured
|
* other NUX dialogs configured
|
||||||
*/
|
*/
|
||||||
if (!unsafe_disableSnooze) {
|
if (!unsafe_disableSnooze) {
|
||||||
// immediately snooze (in memory)
|
// immediately snooze for a day
|
||||||
snoozeNuxDialog()
|
snoozeNuxDialog()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +120,16 @@ function Inner() {
|
||||||
id,
|
id,
|
||||||
completed: true,
|
completed: true,
|
||||||
data: undefined,
|
data: undefined,
|
||||||
|
}).catch(e => {
|
||||||
|
logger.error(`NUX dialogs: failed to upsert '${id}' NUX`, {
|
||||||
|
safeMessage: e.message,
|
||||||
|
})
|
||||||
|
/*
|
||||||
|
* TEMP only intended for use with the 10Milly dialog rn
|
||||||
|
*/
|
||||||
|
if (unsafe_disableSnooze) {
|
||||||
|
__isSnoozedFallback = true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue