aa6aad652e
* thread preferences screen * minor tweaks * more spacing * replace gate with IS_INTERNAL * [Settings] Following feed prefs revamp (#5773) * gated new settings screen * Following feed prefs * Update src/screens/Settings/FollowingFeedPreferences.tsx Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * Update src/screens/Settings/FollowingFeedPreferences.tsx Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * replace pref following feed gate * Update src/screens/Settings/FollowingFeedPreferences.tsx Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * use "Experimental" as the header --------- Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * [Settings] External media prefs revamp (#5774) * gated new settings screen * external media prefs revamp * replace gate ext media embeds * Update src/screens/Settings/ExternalMediaPreferences.tsx Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * add imports for translation * alternate list style on native --------- Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * [Settings] Languages revamp (partial) (#5775) * language settings (lazy restyle) * replace gate * fix text determining flex space * [Settings] App passwords revamp (#5777) * rework app passwords screen * Apply surfdude's copy changes Thanks @surfdude29! Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * format * replace gate * use admonition for input error and animate --------- Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * [Settings] Change handle dialog (#5781) * new change handle dialog * animations native only * overflow hidden on togglebutton animation * add a low-contrast border * extract out copybutton * finish change handle dialog * invalidate query on success * web fixes * error message for rate limit exceeded * typo * em dash! Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * another em dash Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * set maxwidth of suffixtext * Copy tweak Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> --------- Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * [Settings] Notifs settings revamp (#5884) * rename, move, and restyle notif settings * bold "experimental:" --------- Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com>
76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
import React from 'react'
|
|
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
|
|
|
import {STALE} from '#/state/queries'
|
|
import {useAgent} from '#/state/session'
|
|
|
|
const handleQueryKeyRoot = 'handle'
|
|
const fetchHandleQueryKey = (handleOrDid: string) => [
|
|
handleQueryKeyRoot,
|
|
handleOrDid,
|
|
]
|
|
const didQueryKeyRoot = 'did'
|
|
const fetchDidQueryKey = (handleOrDid: string) => [didQueryKeyRoot, handleOrDid]
|
|
|
|
export function useFetchHandle() {
|
|
const queryClient = useQueryClient()
|
|
const agent = useAgent()
|
|
|
|
return React.useCallback(
|
|
async (handleOrDid: string) => {
|
|
if (handleOrDid.startsWith('did:')) {
|
|
const res = await queryClient.fetchQuery({
|
|
staleTime: STALE.MINUTES.FIVE,
|
|
queryKey: fetchHandleQueryKey(handleOrDid),
|
|
queryFn: () => agent.getProfile({actor: handleOrDid}),
|
|
})
|
|
return res.data.handle
|
|
}
|
|
return handleOrDid
|
|
},
|
|
[queryClient, agent],
|
|
)
|
|
}
|
|
|
|
export function useUpdateHandleMutation(opts?: {
|
|
onSuccess?: (handle: string) => void
|
|
}) {
|
|
const queryClient = useQueryClient()
|
|
const agent = useAgent()
|
|
|
|
return useMutation({
|
|
mutationFn: async ({handle}: {handle: string}) => {
|
|
await agent.updateHandle({handle})
|
|
},
|
|
onSuccess(_data, variables) {
|
|
opts?.onSuccess?.(variables.handle)
|
|
queryClient.invalidateQueries({
|
|
queryKey: fetchHandleQueryKey(variables.handle),
|
|
})
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useFetchDid() {
|
|
const queryClient = useQueryClient()
|
|
const agent = useAgent()
|
|
|
|
return React.useCallback(
|
|
async (handleOrDid: string) => {
|
|
return queryClient.fetchQuery({
|
|
staleTime: STALE.INFINITY,
|
|
queryKey: fetchDidQueryKey(handleOrDid),
|
|
queryFn: async () => {
|
|
let identifier = handleOrDid
|
|
if (!identifier.startsWith('did:')) {
|
|
const res = await agent.resolveHandle({handle: identifier})
|
|
identifier = res.data.did
|
|
}
|
|
return identifier
|
|
},
|
|
})
|
|
},
|
|
[queryClient, agent],
|
|
)
|
|
}
|