frontend client for gemstone. decentralised workplace app
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: query for individual invite

serenity 984f58fd 0c2be813

+51
+21
src/queries/get-invite-from-pds.ts
··· 1 + import type { AtUri } from "@/lib/types/atproto"; 2 + import type { SystemsGmstnDevelopmentChannelInvite } from "@/lib/types/lexicon/systems.gmstn.development.channel.invite"; 3 + import { systemsGmstnDevelopmentChannelInviteRecordSchema } from "@/lib/types/lexicon/systems.gmstn.development.channel.invite"; 4 + import { getRecordFromFullAtUri } from "@/lib/utils/atproto"; 5 + import type { Result } from "@/lib/utils/result"; 6 + 7 + export const getInviteFromPds = async ( 8 + atUri: Required<AtUri>, 9 + ): Promise<Result<SystemsGmstnDevelopmentChannelInvite, unknown>> => { 10 + const record = await getRecordFromFullAtUri(atUri); 11 + if (!record.ok) return { ok: false, error: record.error }; 12 + 13 + const { 14 + success, 15 + error, 16 + data: invite, 17 + } = systemsGmstnDevelopmentChannelInviteRecordSchema.safeParse(record.data); 18 + if (!success) return { ok: false, error }; 19 + 20 + return { ok: true, data: invite }; 21 + };
+30
src/queries/hooks/useInviteQuery.ts
··· 1 + import type { AtUri } from "@/lib/types/atproto"; 2 + import { getInviteFromPds } from "@/queries/get-invite-from-pds"; 3 + import { useQuery } from "@tanstack/react-query"; 4 + 5 + export const useInviteQuery = (atUri: Required<AtUri>) => { 6 + const queryKey = ["invite", atUri.authority, atUri.rKey]; 7 + return { 8 + queryKey, 9 + useQuery: () => 10 + useQuery({ 11 + queryKey, 12 + queryFn: async () => { 13 + return await pdsInviteQueryFn(atUri); 14 + }, 15 + }), 16 + }; 17 + }; 18 + 19 + const pdsInviteQueryFn = async (atUri: Required<AtUri>) => { 20 + const invites = await getInviteFromPds(atUri); 21 + 22 + if (!invites.ok) { 23 + console.error("pdsInviteQueryFn error.", invites.error); 24 + throw new Error( 25 + `Something went wrong while getting the user's invite record directly.}`, 26 + ); 27 + } 28 + 29 + return invites.data; 30 + };