From f2fa8ff302cc4ddb60b2d3e532edbe9e04c02e0e Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Fri, 26 Sep 2025 12:40:55 -1000 Subject: [PATCH] add published page block preview --- .../[rkey]/Interactions/Quotes.tsx | 8 +- .../[publication]/[rkey]/PostContent.tsx | 27 ++- .../[did]/[publication]/[rkey]/PostPages.tsx | 9 +- .../[rkey]/PublishedPageBlock.tsx | 159 ++++++++++++++++++ 4 files changed, 191 insertions(+), 12 deletions(-) create mode 100644 app/lish/[did]/[publication]/[rkey]/PublishedPageBlock.tsx diff --git a/app/lish/[did]/[publication]/[rkey]/Interactions/Quotes.tsx b/app/lish/[did]/[publication]/[rkey]/Interactions/Quotes.tsx index 8b3ae0ba..58cbd732 100644 --- a/app/lish/[did]/[publication]/[rkey]/Interactions/Quotes.tsx +++ b/app/lish/[did]/[publication]/[rkey]/Interactions/Quotes.tsx @@ -26,7 +26,8 @@ export const Quotes = (props: { }) => { let data = useContext(PostPageContext); const document_uri = data?.uri; - if (!document_uri) throw new Error('document_uri not available in PostPageContext'); + if (!document_uri) + throw new Error("document_uri not available in PostPageContext"); return (
@@ -34,7 +35,9 @@ export const Quotes = (props: { Quotes @@ -125,6 +128,7 @@ export const QuoteContent = (props: { >
; bskyPostData: AppBskyFeedDefs.PostView[]; + pages: PubLeafletPagesLinearDocument.Main[]; }) { return (
; bskyPostData: AppBskyFeedDefs.PostView[]; @@ -123,14 +130,16 @@ let Block = ({ switch (true) { case PubLeafletBlocksPage.isMain(b.block): { let id = b.block.id; + let page = pages.find((p) => p.id === id); + if (!page) return; return ( -
{ - openPage(pageId, id); - }} - > - ITS A BLOCK -
+ ); } case PubLeafletBlocksBskyPost.isMain(b.block): { @@ -159,6 +168,7 @@ let Block = ({
    {b.block.children.map((child, i) => ( {props.item.children.map((child, index) => (
    ({ pages: [] as string[], })); @@ -73,6 +74,7 @@ export function PostPages({ let hasPageBackground = !!pubRecord.theme?.showPageBackground; let fullPageScroll = !hasPageBackground && !drawerOpen && pages.length === 0; + let record = document.data as PubLeafletDocument.Record; return ( <> {!fullPageScroll && } @@ -88,6 +90,7 @@ export function PostPages({ preferences={preferences} /> { - let record = document.data as PubLeafletDocument.Record; let page = record.pages.find( (page) => (page as PubLeafletPagesLinearDocument.Main).id === p, ) as PubLeafletPagesLinearDocument.Main | undefined; if (!page) return null; return ( - <> + - + ); })} {!fullPageScroll && } diff --git a/app/lish/[did]/[publication]/[rkey]/PublishedPageBlock.tsx b/app/lish/[did]/[publication]/[rkey]/PublishedPageBlock.tsx new file mode 100644 index 00000000..3a66db80 --- /dev/null +++ b/app/lish/[did]/[publication]/[rkey]/PublishedPageBlock.tsx @@ -0,0 +1,159 @@ +"use client"; + +import { useEntity, useReplicache } from "src/replicache"; +import { useUIState } from "src/useUIState"; +import { CSSProperties, useContext, useRef } from "react"; +import { useCardBorderHidden } from "components/Pages/useCardBorderHidden"; +import { PostContent } from "./PostContent"; +import { + PubLeafletBlocksHeader, + PubLeafletBlocksText, + PubLeafletPagesLinearDocument, + PubLeafletPublication, +} from "lexicons/api"; +import { AppBskyFeedDefs } from "@atproto/api"; +import { TextBlock } from "./TextBlock"; +import { PostPageContext } from "./PostPageContext"; +import { openPage, usePostPageUIState } from "./PostPages"; + +export function PublishedPageLinkBlock(props: { + blocks: PubLeafletPagesLinearDocument.Block[]; + parentPageId: string | undefined; + pageId: string; + did: string; + preview?: boolean; + className?: string; + prerenderedCodeBlocks?: Map; + bskyPostData: AppBskyFeedDefs.PostView[]; +}) { + //switch to use actually state + let isOpen = usePostPageUIState((s) => s.pages.includes(props.pageId)); + return ( +
    { + if (e.isDefaultPrevented()) return; + if (e.shiftKey) return; + e.preventDefault(); + e.stopPropagation(); + + console.log("yoo@"); + + openPage(props.parentPageId, props.pageId); + //open the damn thing somehow + }} + > + +
    + ); +} +export function DocLinkBlock(props: { + blocks: PubLeafletPagesLinearDocument.Block[]; + pageId?: string; + did: string; + preview?: boolean; + className?: string; + prerenderedCodeBlocks?: Map; + bskyPostData: AppBskyFeedDefs.PostView[]; +}) { + let { rep } = useReplicache(); + let [title, description] = props.blocks + .map((b) => b.block) + .filter( + (b) => PubLeafletBlocksText.isMain(b) || PubLeafletBlocksHeader.isMain(b), + ); + + return ( +
    + <> +
    +
    + {title && ( +
    + +
    + )} + {description && ( +
    + +
    + )} +
    + {!props.preview && ( + + )} +
    + +
    + ); +} + +export function PagePreview(props: { + did: string; + blocks: PubLeafletPagesLinearDocument.Block[]; +}) { + let previewRef = useRef(null); + let { rootEntity } = useReplicache(); + let data = useContext(PostPageContext); + let theme = data?.documents_in_publications[0]?.publications + ?.record as PubLeafletPublication.Record; + let pageWidth = `var(--page-width-unitless)`; + let cardBorderHidden = !theme.theme?.showPageBackground; + return ( +
    +
    + {!cardBorderHidden && ( +
    + )} + +
    +
    + ); +} -- 2.54.0