Bluesky app fork with some witchin' additions 💫 witchsky.app
bluesky fork client

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

authored by

Eric Bailey and committed by
GitHub
3ab6c435 143e2c80

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