a tool for shared writing and social publishing

add profile data to post page

+53 -26
+53 -26
app/lish/[did]/[publication]/[rkey]/page.tsx
··· 14 14 import { getPublicationURL } from "app/lish/createPub/getPublicationURL"; 15 15 import { TextBlock } from "./TextBlock"; 16 16 import { ThemeProvider } from "components/ThemeManager/ThemeProvider"; 17 + import { BskyAgent } from "@atproto/api"; 17 18 18 19 export async function generateMetadata(props: { 19 20 params: Promise<{ publication: string; did: string; rkey: string }>; ··· 21 22 let did = decodeURIComponent((await props.params).did); 22 23 if (!did) return { title: "Publication 404" }; 23 24 24 - let { data: document } = await supabaseServerClient 25 - .from("documents") 26 - .select("*") 27 - .eq( 28 - "uri", 29 - AtUri.make(did, ids.PubLeafletDocument, (await props.params).rkey), 30 - ) 31 - .single(); 25 + let [{ data: document }] = await Promise.all([ 26 + supabaseServerClient 27 + .from("documents") 28 + .select("*") 29 + .eq( 30 + "uri", 31 + AtUri.make(did, ids.PubLeafletDocument, (await props.params).rkey), 32 + ) 33 + .single(), 34 + ]); 32 35 33 36 if (!document) return { title: "404" }; 34 37 let record = document.data as PubLeafletDocument.Record; ··· 44 47 }) { 45 48 let did = decodeURIComponent((await props.params).did); 46 49 if (!did) return <div> can't resolve handle</div>; 47 - let { data: document } = await supabaseServerClient 48 - .from("documents") 49 - .select("*, documents_in_publications(publications(*))") 50 - .eq( 51 - "uri", 52 - AtUri.make(did, ids.PubLeafletDocument, (await props.params).rkey), 53 - ) 54 - .single(); 50 + let agent = new BskyAgent({ service: "https://public.api.bsky.app" }); 51 + let [{ data: document }, { data: profile }] = await Promise.all([ 52 + supabaseServerClient 53 + .from("documents") 54 + .select("*, documents_in_publications(publications(*))") 55 + .eq( 56 + "uri", 57 + AtUri.make(did, ids.PubLeafletDocument, (await props.params).rkey), 58 + ) 59 + .single(), 60 + agent.getProfile({ actor: did }), 61 + ]); 55 62 if (!document?.data || !document.documents_in_publications[0].publications) 56 63 return <div>notfound</div>; 57 64 let record = document.data as PubLeafletDocument.Record; ··· 78 85 {record.description ? ( 79 86 <p className="italic text-secondary">{record.description}</p> 80 87 ) : null} 81 - {record.publishedAt ? ( 82 - <p className="text-sm text-tertiary pt-3"> 83 - Published{" "} 84 - {new Date(record.publishedAt).toLocaleDateString(undefined, { 85 - year: "numeric", 86 - month: "long", 87 - day: "2-digit", 88 - })} 89 - </p> 90 - ) : null} 88 + 89 + <div className="text-sm text-tertiary pt-3 flex gap-1"> 90 + {profile ? ( 91 + <> 92 + <a 93 + className="text-tertiary" 94 + href={`https://bsky.app/profile/${profile.handle}`} 95 + > 96 + by {profile.displayName} 97 + </a> 98 + </> 99 + ) : null} 100 + {record.publishedAt ? ( 101 + <> 102 + {" "} 103 + | 104 + <p> 105 + Published{" "} 106 + {new Date(record.publishedAt).toLocaleDateString( 107 + undefined, 108 + { 109 + year: "numeric", 110 + month: "long", 111 + day: "2-digit", 112 + }, 113 + )} 114 + </p> 115 + </> 116 + ) : null} 117 + </div> 91 118 </div> 92 119 <div className="postContent flex flex-col "> 93 120 {blocks.map((b, index) => {