Handle pressing all go.bsky.app links in-app w/ resolution (#4680)
This commit is contained in:
parent
030c8e268e
commit
91c4aa7c2d
9 changed files with 186 additions and 17 deletions
24
src/state/queries/resolve-short-link.ts
Normal file
24
src/state/queries/resolve-short-link.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import {useQuery} from '@tanstack/react-query'
|
||||
|
||||
import {resolveShortLink} from 'lib/link-meta/resolve-short-link'
|
||||
import {parseStarterPackUri} from 'lib/strings/starter-pack'
|
||||
import {STALE} from 'state/queries/index'
|
||||
|
||||
const ROOT_URI = 'https://go.bsky.app/'
|
||||
|
||||
const RQKEY_ROOT = 'resolved-short-link'
|
||||
export const RQKEY = (code: string) => [RQKEY_ROOT, code]
|
||||
|
||||
export function useResolvedStarterPackShortLink({code}: {code: string}) {
|
||||
return useQuery({
|
||||
queryKey: RQKEY(code),
|
||||
queryFn: async () => {
|
||||
const uri = `${ROOT_URI}${code}`
|
||||
const res = await resolveShortLink(uri)
|
||||
return parseStarterPackUri(res)
|
||||
},
|
||||
retry: 1,
|
||||
enabled: Boolean(code),
|
||||
staleTime: STALE.HOURS.ONE,
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue