Trim back prefs exposure in NUXs, make naming more friendly (#6980)
This commit is contained in:
@@ -3,12 +3,7 @@ import {AppBskyActorDefs} from '@atproto/api'
|
|||||||
|
|
||||||
import {useGate} from '#/lib/statsig/statsig'
|
import {useGate} from '#/lib/statsig/statsig'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {
|
import {Nux, useNuxs, useResetNuxs, useSaveNux} from '#/state/queries/nuxs'
|
||||||
Nux,
|
|
||||||
useNuxs,
|
|
||||||
useRemoveNuxsMutation,
|
|
||||||
useUpsertNuxMutation,
|
|
||||||
} from '#/state/queries/nuxs'
|
|
||||||
import {
|
import {
|
||||||
usePreferencesQuery,
|
usePreferencesQuery,
|
||||||
UsePreferencesQueryResponse,
|
UsePreferencesQueryResponse,
|
||||||
@@ -85,8 +80,8 @@ function Inner({
|
|||||||
return isSnoozed()
|
return isSnoozed()
|
||||||
})
|
})
|
||||||
const [activeNux, setActiveNux] = React.useState<Nux | undefined>()
|
const [activeNux, setActiveNux] = React.useState<Nux | undefined>()
|
||||||
const {mutateAsync: upsertNux} = useUpsertNuxMutation()
|
const {mutateAsync: saveNux} = useSaveNux()
|
||||||
const {mutate: removeNuxs} = useRemoveNuxsMutation()
|
const {mutate: resetNuxs} = useResetNuxs()
|
||||||
|
|
||||||
const snoozeNuxDialog = React.useCallback(() => {
|
const snoozeNuxDialog = React.useCallback(() => {
|
||||||
snooze()
|
snooze()
|
||||||
@@ -102,7 +97,7 @@ function Inner({
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
window.clearNuxDialog = (id: Nux) => {
|
window.clearNuxDialog = (id: Nux) => {
|
||||||
if (!IS_DEV || !id) return
|
if (!IS_DEV || !id) return
|
||||||
removeNuxs([id])
|
resetNuxs([id])
|
||||||
unsnooze()
|
unsnooze()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,7 +131,7 @@ function Inner({
|
|||||||
snoozeNuxDialog()
|
snoozeNuxDialog()
|
||||||
|
|
||||||
// immediately update remote data (affects next reload)
|
// immediately update remote data (affects next reload)
|
||||||
upsertNux({
|
saveNux({
|
||||||
id,
|
id,
|
||||||
completed: true,
|
completed: true,
|
||||||
data: undefined,
|
data: undefined,
|
||||||
@@ -152,7 +147,7 @@ function Inner({
|
|||||||
nuxs,
|
nuxs,
|
||||||
snoozed,
|
snoozed,
|
||||||
snoozeNuxDialog,
|
snoozeNuxDialog,
|
||||||
upsertNux,
|
saveNux,
|
||||||
gate,
|
gate,
|
||||||
currentAccount,
|
currentAccount,
|
||||||
currentProfile,
|
currentProfile,
|
||||||
|
|||||||
@@ -10,49 +10,78 @@ import {useAgent} from '#/state/session'
|
|||||||
|
|
||||||
export {Nux} from '#/state/queries/nuxs/definitions'
|
export {Nux} from '#/state/queries/nuxs/definitions'
|
||||||
|
|
||||||
export function useNuxs() {
|
export function useNuxs():
|
||||||
const {data, ...rest} = usePreferencesQuery()
|
| {
|
||||||
|
nuxs: AppNux[]
|
||||||
|
status: 'ready'
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
nuxs: undefined
|
||||||
|
status: 'loading' | 'error'
|
||||||
|
} {
|
||||||
|
const {data, isSuccess, isError} = usePreferencesQuery()
|
||||||
|
const status = isSuccess ? 'ready' : isError ? 'error' : 'loading'
|
||||||
|
|
||||||
if (data && rest.isSuccess) {
|
if (status === 'ready') {
|
||||||
const nuxs = data.bskyAppState.nuxs
|
const nuxs = data?.bskyAppState?.nuxs
|
||||||
?.map(parseAppNux)
|
?.map(parseAppNux)
|
||||||
?.filter(Boolean) as AppNux[]
|
?.filter(Boolean) as AppNux[]
|
||||||
|
|
||||||
if (nuxs) {
|
if (nuxs) {
|
||||||
return {
|
return {
|
||||||
nuxs,
|
nuxs,
|
||||||
...rest,
|
status,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
nuxs: [],
|
||||||
|
status,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
nuxs: undefined,
|
nuxs: undefined,
|
||||||
...rest,
|
status,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useNux<T extends Nux>(id: T) {
|
export function useNux<T extends Nux>(
|
||||||
const {nuxs, ...rest} = useNuxs()
|
id: T,
|
||||||
|
):
|
||||||
|
| {
|
||||||
|
nux: Extract<AppNux, {id: T}> | undefined
|
||||||
|
status: 'ready'
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
nux: undefined
|
||||||
|
status: 'loading' | 'error'
|
||||||
|
} {
|
||||||
|
const {nuxs, status} = useNuxs()
|
||||||
|
|
||||||
if (nuxs && rest.isSuccess) {
|
if (status === 'ready') {
|
||||||
const nux = nuxs.find(nux => nux.id === id)
|
const nux = nuxs.find(nux => nux.id === id)
|
||||||
|
|
||||||
if (nux) {
|
if (nux) {
|
||||||
return {
|
return {
|
||||||
nux: nux as Extract<AppNux, {id: T}>,
|
nux: nux as Extract<AppNux, {id: T}>,
|
||||||
...rest,
|
status,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
nux: undefined,
|
||||||
|
status,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
nux: undefined,
|
nux: undefined,
|
||||||
...rest,
|
status,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useUpsertNuxMutation() {
|
export function useSaveNux() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
|
|
||||||
@@ -68,7 +97,7 @@ export function useUpsertNuxMutation() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useRemoveNuxsMutation() {
|
export function useResetNuxs() {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user