diff options
author | Hailey <me@haileyok.com> | 2024-06-27 19:35:20 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-27 19:35:20 -0700 |
commit | 91c4aa7c2dc598dd5e2c828e44c0d2c94cf0967d (patch) | |
tree | 362f79f88bab8107053c1fe0201ddcb4d0d21ac5 /src/state/queries | |
parent | 030c8e268e161bebe360e3ad97b1c18bd8425ca8 (diff) | |
download | voidsky-91c4aa7c2dc598dd5e2c828e44c0d2c94cf0967d.tar.zst |
Handle pressing all go.bsky.app links in-app w/ resolution (#4680)
Diffstat (limited to 'src/state/queries')
-rw-r--r-- | src/state/queries/resolve-short-link.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/state/queries/resolve-short-link.ts b/src/state/queries/resolve-short-link.ts new file mode 100644 index 000000000..a10bc12c1 --- /dev/null +++ b/src/state/queries/resolve-short-link.ts @@ -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, + }) +} |