a tool for shared writing and social publishing

get theme from correct place and fix pub metadata

+64 -29
+2 -5
app/[leaflet_id]/page.tsx
··· 13 13 import { supabaseServerClient } from "supabase/serverClient"; 14 14 import { get_leaflet_data } from "app/api/rpc/[command]/get_leaflet_data"; 15 15 import { NotFoundLayout } from "components/PageLayouts/NotFoundLayout"; 16 + import { getPublicationMetadataFromLeafletData } from "src/utils/getPublicationMetadataFromLeafletData"; 16 17 17 18 export const preferredRegion = ["sfo1"]; 18 19 export const dynamic = "force-dynamic"; ··· 70 71 ); 71 72 let rootEntity = res.data?.root_entity; 72 73 if (!rootEntity || !res.data) return { title: "Leaflet not found" }; 73 - let publication_data = 74 - res.data?.leaflets_in_publications?.[0] || 75 - res.data?.permission_token_rights[0].entity_sets?.permission_tokens?.find( 76 - (p) => p.leaflets_in_publications.length, 77 - )?.leaflets_in_publications?.[0]; 74 + let publication_data = getPublicationMetadataFromLeafletData(res.data); 78 75 if (publication_data) { 79 76 return { 80 77 title: publication_data.title || "Untitled",
+2 -3
app/lish/[did]/[publication]/[rkey]/PublishedPageBlock.tsx
··· 151 151 let previewRef = useRef<HTMLDivElement | null>(null); 152 152 let { rootEntity } = useReplicache(); 153 153 let data = useContext(PostPageContext); 154 - let theme = data?.documents_in_publications[0]?.publications 155 - ?.record as PubLeafletPublication.Record; 154 + let theme = data?.theme; 156 155 let pageWidth = `var(--page-width-unitless)`; 157 - let cardBorderHidden = !theme.theme?.showPageBackground; 156 + let cardBorderHidden = !theme?.showPageBackground; 158 157 return ( 159 158 <div 160 159 ref={previewRef}
+8 -1
app/lish/[did]/[publication]/[rkey]/getPostPageData.ts
··· 1 1 import { supabaseServerClient } from "supabase/serverClient"; 2 2 import { AtUri } from "@atproto/syntax"; 3 - import { PubLeafletPublication } from "lexicons/api"; 3 + import { PubLeafletDocument, PubLeafletPublication } from "lexicons/api"; 4 4 5 5 export async function getPostPageData(uri: string) { 6 6 let { data: document } = await supabaseServerClient ··· 43 43 ...uniqueBacklinks, 44 44 ]; 45 45 46 + let theme = 47 + ( 48 + document?.documents_in_publications[0]?.publications 49 + ?.record as PubLeafletPublication.Record 50 + )?.theme || (document?.data as PubLeafletDocument.Record)?.theme; 51 + 46 52 return { 47 53 ...document, 48 54 quotesAndMentions, 55 + theme, 49 56 }; 50 57 } 51 58
+2 -20
components/PageSWRDataProvider.tsx
··· 7 7 import { getPollData } from "actions/pollActions"; 8 8 import type { GetLeafletDataReturnType } from "app/api/rpc/[command]/get_leaflet_data"; 9 9 import { createContext, useContext } from "react"; 10 + import { getPublicationMetadataFromLeafletData } from "src/utils/getPublicationMetadataFromLeafletData"; 10 11 11 12 export const StaticLeafletDataContext = createContext< 12 13 null | GetLeafletDataReturnType["result"]["data"] ··· 68 69 let { data, mutate } = useLeafletData(); 69 70 70 71 // First check for leaflets in publications 71 - let pubData = 72 - data?.leaflets_in_publications?.[0] || 73 - data?.permission_token_rights[0].entity_sets?.permission_tokens?.find( 74 - (p) => p.leaflets_in_publications.length, 75 - )?.leaflets_in_publications?.[0]; 76 - 77 - // If not found, check for standalone documents 78 - let standaloneDoc = 79 - data?.leaflets_to_documents?.[0] || 80 - data?.permission_token_rights[0].entity_sets?.permission_tokens.find( 81 - (p) => p.leaflets_to_documents.length, 82 - )?.leaflets_to_documents?.[0]; 83 - if (!pubData && standaloneDoc) { 84 - // Transform standalone document data to match the expected format 85 - pubData = { 86 - ...standaloneDoc, 87 - publications: null, // No publication for standalone docs 88 - doc: standaloneDoc.document, 89 - } as any; 90 - } 72 + let pubData = getPublicationMetadataFromLeafletData(data); 91 73 92 74 return { 93 75 data: pubData || null,
+50
src/utils/getPublicationMetadataFromLeafletData.ts
··· 1 + import { GetLeafletDataReturnType } from "app/api/rpc/[command]/get_leaflet_data"; 2 + import { Json } from "supabase/database.types"; 3 + 4 + export function getPublicationMetadataFromLeafletData( 5 + data?: GetLeafletDataReturnType["result"]["data"], 6 + ) { 7 + if (!data) return null; 8 + 9 + let pubData: 10 + | { 11 + description: string; 12 + title: string; 13 + leaflet: string; 14 + doc: string | null; 15 + publications: { 16 + identity_did: string; 17 + name: string; 18 + indexed_at: string; 19 + record: Json | null; 20 + uri: string; 21 + } | null; 22 + documents: { 23 + data: Json; 24 + indexed_at: string; 25 + uri: string; 26 + } | null; 27 + } 28 + | undefined 29 + | null = 30 + data?.leaflets_in_publications?.[0] || 31 + data?.permission_token_rights[0].entity_sets?.permission_tokens?.find( 32 + (p) => p.leaflets_in_publications.length, 33 + )?.leaflets_in_publications?.[0]; 34 + 35 + // If not found, check for standalone documents 36 + let standaloneDoc = 37 + data?.leaflets_to_documents?.[0] || 38 + data?.permission_token_rights[0].entity_sets?.permission_tokens.find( 39 + (p) => p.leaflets_to_documents.length, 40 + )?.leaflets_to_documents?.[0]; 41 + if (!pubData && standaloneDoc) { 42 + // Transform standalone document data to match the expected format 43 + pubData = { 44 + ...standaloneDoc, 45 + publications: null, // No publication for standalone docs 46 + doc: standaloneDoc.document, 47 + }; 48 + } 49 + return pubData; 50 + }