Bluesky app fork with some witchin' additions 💫

Trim back prefs exposure in NUXs, make naming more friendly (#6980)

authored by Eric Bailey and committed by GitHub 3ab6c435 143e2c80

Changed files
+48 -24
src
components
dialogs
nuxs
state
queries
nuxs
+6 -11
src/components/dialogs/nuxs/index.tsx
··· 3 3 4 4 import {useGate} from '#/lib/statsig/statsig' 5 5 import {logger} from '#/logger' 6 - import { 7 - Nux, 8 - useNuxs, 9 - useRemoveNuxsMutation, 10 - useUpsertNuxMutation, 11 - } from '#/state/queries/nuxs' 6 + import {Nux, useNuxs, useResetNuxs, useSaveNux} from '#/state/queries/nuxs' 12 7 import { 13 8 usePreferencesQuery, 14 9 UsePreferencesQueryResponse, ··· 85 80 return isSnoozed() 86 81 }) 87 82 const [activeNux, setActiveNux] = React.useState<Nux | undefined>() 88 - const {mutateAsync: upsertNux} = useUpsertNuxMutation() 89 - const {mutate: removeNuxs} = useRemoveNuxsMutation() 83 + const {mutateAsync: saveNux} = useSaveNux() 84 + const {mutate: resetNuxs} = useResetNuxs() 90 85 91 86 const snoozeNuxDialog = React.useCallback(() => { 92 87 snooze() ··· 102 97 // @ts-ignore 103 98 window.clearNuxDialog = (id: Nux) => { 104 99 if (!IS_DEV || !id) return 105 - removeNuxs([id]) 100 + resetNuxs([id]) 106 101 unsnooze() 107 102 } 108 103 } ··· 136 131 snoozeNuxDialog() 137 132 138 133 // immediately update remote data (affects next reload) 139 - upsertNux({ 134 + saveNux({ 140 135 id, 141 136 completed: true, 142 137 data: undefined, ··· 152 147 nuxs, 153 148 snoozed, 154 149 snoozeNuxDialog, 155 - upsertNux, 150 + saveNux, 156 151 gate, 157 152 currentAccount, 158 153 currentProfile,
+42 -13
src/state/queries/nuxs/index.ts
··· 10 10 11 11 export {Nux} from '#/state/queries/nuxs/definitions' 12 12 13 - export function useNuxs() { 14 - const {data, ...rest} = usePreferencesQuery() 13 + export function useNuxs(): 14 + | { 15 + nuxs: AppNux[] 16 + status: 'ready' 17 + } 18 + | { 19 + nuxs: undefined 20 + status: 'loading' | 'error' 21 + } { 22 + const {data, isSuccess, isError} = usePreferencesQuery() 23 + const status = isSuccess ? 'ready' : isError ? 'error' : 'loading' 15 24 16 - if (data && rest.isSuccess) { 17 - const nuxs = data.bskyAppState.nuxs 25 + if (status === 'ready') { 26 + const nuxs = data?.bskyAppState?.nuxs 18 27 ?.map(parseAppNux) 19 28 ?.filter(Boolean) as AppNux[] 20 29 21 30 if (nuxs) { 22 31 return { 23 32 nuxs, 24 - ...rest, 33 + status, 34 + } 35 + } else { 36 + return { 37 + nuxs: [], 38 + status, 25 39 } 26 40 } 27 41 } 28 42 29 43 return { 30 44 nuxs: undefined, 31 - ...rest, 45 + status, 32 46 } 33 47 } 34 48 35 - export function useNux<T extends Nux>(id: T) { 36 - const {nuxs, ...rest} = useNuxs() 49 + export function useNux<T extends Nux>( 50 + id: T, 51 + ): 52 + | { 53 + nux: Extract<AppNux, {id: T}> | undefined 54 + status: 'ready' 55 + } 56 + | { 57 + nux: undefined 58 + status: 'loading' | 'error' 59 + } { 60 + const {nuxs, status} = useNuxs() 37 61 38 - if (nuxs && rest.isSuccess) { 62 + if (status === 'ready') { 39 63 const nux = nuxs.find(nux => nux.id === id) 40 64 41 65 if (nux) { 42 66 return { 43 67 nux: nux as Extract<AppNux, {id: T}>, 44 - ...rest, 68 + status, 69 + } 70 + } else { 71 + return { 72 + nux: undefined, 73 + status, 45 74 } 46 75 } 47 76 } 48 77 49 78 return { 50 79 nux: undefined, 51 - ...rest, 80 + status, 52 81 } 53 82 } 54 83 55 - export function useUpsertNuxMutation() { 84 + export function useSaveNux() { 56 85 const queryClient = useQueryClient() 57 86 const agent = useAgent() 58 87 ··· 68 97 }) 69 98 } 70 99 71 - export function useRemoveNuxsMutation() { 100 + export function useResetNuxs() { 72 101 const queryClient = useQueryClient() 73 102 const agent = useAgent() 74 103