From c85cb855f7437eab02bd90c73962b8dc1d411b2d Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Wed, 21 May 2025 17:02:43 -0400 Subject: [PATCH] add profile data to post page --- app/lish/[did]/[publication]/[rkey]/page.tsx | 79 +++++++++++++------- 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/app/lish/[did]/[publication]/[rkey]/page.tsx b/app/lish/[did]/[publication]/[rkey]/page.tsx index 02a50b59..729f9a77 100644 --- a/app/lish/[did]/[publication]/[rkey]/page.tsx +++ b/app/lish/[did]/[publication]/[rkey]/page.tsx @@ -14,6 +14,7 @@ import { Metadata } from "next"; import { getPublicationURL } from "app/lish/createPub/getPublicationURL"; import { TextBlock } from "./TextBlock"; import { ThemeProvider } from "components/ThemeManager/ThemeProvider"; +import { BskyAgent } from "@atproto/api"; export async function generateMetadata(props: { params: Promise<{ publication: string; did: string; rkey: string }>; @@ -21,14 +22,16 @@ export async function generateMetadata(props: { let did = decodeURIComponent((await props.params).did); if (!did) return { title: "Publication 404" }; - let { data: document } = await supabaseServerClient - .from("documents") - .select("*") - .eq( - "uri", - AtUri.make(did, ids.PubLeafletDocument, (await props.params).rkey), - ) - .single(); + let [{ data: document }] = await Promise.all([ + supabaseServerClient + .from("documents") + .select("*") + .eq( + "uri", + AtUri.make(did, ids.PubLeafletDocument, (await props.params).rkey), + ) + .single(), + ]); if (!document) return { title: "404" }; let record = document.data as PubLeafletDocument.Record; @@ -44,14 +47,18 @@ export default async function Post(props: { }) { let did = decodeURIComponent((await props.params).did); if (!did) return
can't resolve handle
; - let { data: document } = await supabaseServerClient - .from("documents") - .select("*, documents_in_publications(publications(*))") - .eq( - "uri", - AtUri.make(did, ids.PubLeafletDocument, (await props.params).rkey), - ) - .single(); + let agent = new BskyAgent({ service: "https://public.api.bsky.app" }); + let [{ data: document }, { data: profile }] = await Promise.all([ + supabaseServerClient + .from("documents") + .select("*, documents_in_publications(publications(*))") + .eq( + "uri", + AtUri.make(did, ids.PubLeafletDocument, (await props.params).rkey), + ) + .single(), + agent.getProfile({ actor: did }), + ]); if (!document?.data || !document.documents_in_publications[0].publications) return
notfound
; let record = document.data as PubLeafletDocument.Record; @@ -78,16 +85,36 @@ export default async function Post(props: { {record.description ? (

{record.description}

) : null} - {record.publishedAt ? ( -

- Published{" "} - {new Date(record.publishedAt).toLocaleDateString(undefined, { - year: "numeric", - month: "long", - day: "2-digit", - })} -

- ) : null} + +
+ {profile ? ( + <> + + by {profile.displayName} + + + ) : null} + {record.publishedAt ? ( + <> + {" "} + | +

+ Published{" "} + {new Date(record.publishedAt).toLocaleDateString( + undefined, + { + year: "numeric", + month: "long", + day: "2-digit", + }, + )} +

+ + ) : null} +
{blocks.map((b, index) => { -- 2.54.0