diff --git a/src/components/UniversalPostRenderer.tsx b/src/components/UniversalPostRenderer.tsx index d362666..22aa370 100644 --- a/src/components/UniversalPostRenderer.tsx +++ b/src/components/UniversalPostRenderer.tsx @@ -1,4 +1,5 @@ import * as ATPAPI from "@atproto/api"; +import { useQuery } from "@tanstack/react-query"; import { useNavigate } from "@tanstack/react-router"; import DOMPurify from "dompurify"; import { useAtom } from "jotai"; @@ -16,6 +17,7 @@ import { } from "~/utils/atoms"; import { useHydratedEmbed } from "~/utils/useHydrated"; import { + constructConstellationQuery, useQueryArbitrary, useQueryConstellation, useQueryIdentity, @@ -2143,9 +2145,82 @@ const stopgap = { }; function PollEmbed({ did, rkey }: { did: string; rkey: string }) { + const { agent } = useAuth(); const pollUri = `at://${did}/app.reddwarf.embed.poll/${rkey}`; const { data: pollRecord, isLoading, error } = useQueryArbitrary(pollUri); + // Query vote counts for each option + const [constellationurl] = useAtom(constellationURLAtom); + + const { data: voteCountsA } = useQueryConstellation({ + method: "/links/count/distinct-dids", + target: pollUri, + collection: "app.reddwarf.poll.vote.a", + path: ".subject.uri", + }); + + const { data: voteCountsB } = useQueryConstellation({ + method: "/links/count/distinct-dids", + target: pollUri, + collection: "app.reddwarf.poll.vote.b", + path: ".subject.uri", + }); + + const { data: voteCountsC } = useQueryConstellation({ + method: "/links/count/distinct-dids", + target: pollUri, + collection: "app.reddwarf.poll.vote.c", + path: ".subject.uri", + }); + + const { data: voteCountsD } = useQueryConstellation({ + method: "/links/count/distinct-dids", + target: pollUri, + collection: "app.reddwarf.poll.vote.d", + path: ".subject.uri", + }); + + // Query first page of voters for each option to get PFPs + const { data: votersA } = useQuery( + constructConstellationQuery({ + constellation: constellationurl, + method: "/links", + target: pollUri, + collection: "app.reddwarf.poll.vote.a", + path: ".subject.uri", + }), + ); + + const { data: votersB } = useQuery( + constructConstellationQuery({ + constellation: constellationurl, + method: "/links", + target: pollUri, + collection: "app.reddwarf.poll.vote.b", + path: ".subject.uri", + }), + ); + + const { data: votersC } = useQuery( + constructConstellationQuery({ + constellation: constellationurl, + method: "/links", + target: pollUri, + collection: "app.reddwarf.poll.vote.c", + path: ".subject.uri", + }), + ); + + const { data: votersD } = useQuery( + constructConstellationQuery({ + constellation: constellationurl, + method: "/links", + target: pollUri, + collection: "app.reddwarf.poll.vote.d", + path: ".subject.uri", + }), + ); + if (isLoading) { return (