a tool for shared writing and social publishing

add profile data to pub page

+34 -12
+34 -12
app/lish/[did]/[publication]/page.tsx
··· 5 5 import React from "react"; 6 6 import { get_publication_data } from "app/api/rpc/[command]/get_publication_data"; 7 7 import { AtUri } from "@atproto/syntax"; 8 - import { PubLeafletDocument, PubLeafletPublication } from "lexicons/api"; 8 + import { 9 + AtpBaseClient, 10 + PubLeafletDocument, 11 + PubLeafletPublication, 12 + } from "lexicons/api"; 9 13 import Link from "next/link"; 10 14 import { getPublicationURL } from "app/lish/createPub/getPublicationURL"; 15 + import { BskyAgent } from "@atproto/api"; 11 16 12 17 export async function generateMetadata(props: { 13 18 params: Promise<{ publication: string; did: string }>; ··· 33 38 let params = await props.params; 34 39 let did = decodeURIComponent(params.did); 35 40 if (!did) return <PubNotFound />; 36 - let { data: publication } = await supabaseServerClient 37 - .from("publications") 38 - .select( 39 - `*, 41 + let agent = new BskyAgent({ service: "https://public.api.bsky.app" }); 42 + let [{ data: publication }, { data: profile }] = await Promise.all([ 43 + supabaseServerClient 44 + .from("publications") 45 + .select( 46 + `*, 40 47 documents_in_publications(documents(*)) 41 48 `, 42 - ) 43 - .eq("identity_did", did) 44 - .eq("name", decodeURIComponent(params.publication)) 45 - .single(); 49 + ) 50 + .eq("identity_did", did) 51 + .eq("name", decodeURIComponent(params.publication)) 52 + .single(), 53 + agent.getProfile({ actor: did }), 54 + ]); 46 55 47 - let record = publication?.record as PubLeafletPublication.Record; 56 + let record = publication?.record as PubLeafletPublication.Record | null; 48 57 49 58 if (!publication) return <PubNotFound />; 50 59 try { ··· 54 63 <div className="publication max-w-prose w-full mx-auto h-full sm:pt-8 pt-4 px-3 pb-12 sm:pb-8"> 55 64 <div className="flex flex-col pb-8 w-full text-center justify-center "> 56 65 <div className="flex flex-col gap-3 justify-center place-items-center"> 57 - {record.icon && ( 66 + {record?.icon && ( 58 67 <div 59 68 className="shrink-0 w-10 h-10 rounded-full" 60 69 style={{ ··· 69 78 {publication.name} 70 79 </h2> 71 80 </div> 72 - <p className="sm:text-lg text-tertiary">{record.description} </p> 81 + <p className="sm:text-lg text-tertiary">{record?.description} </p> 82 + {profile && ( 83 + <p className="italic"> 84 + <strong className="text-secondary"> 85 + by {profile.displayName} 86 + </strong>{" "} 87 + <a 88 + className="text-tertiary" 89 + href={`https://bsky.app/profile/${profile.handle}`} 90 + > 91 + @{profile.handle} 92 + </a> 93 + </p> 94 + )} 73 95 </div> 74 96 <div className="publicationPostList w-full flex flex-col gap-4"> 75 97 {publication.documents_in_publications