diff --git a/app/(app)/lish/[did]/[publication]/[rkey]/Blocks/PublishedPageBlock.tsx b/app/(app)/lish/[did]/[publication]/[rkey]/Blocks/PublishedPageBlock.tsx index 25efe8ee..0a4f5cd9 100644 --- a/app/(app)/lish/[did]/[publication]/[rkey]/Blocks/PublishedPageBlock.tsx +++ b/app/(app)/lish/[did]/[publication]/[rkey]/Blocks/PublishedPageBlock.tsx @@ -2,13 +2,12 @@ import { useEntity, useReplicache } from "src/replicache"; import { useUIState } from "src/useUIState"; -import { CSSProperties, useRef, useState } from "react"; +import { CSSProperties, useRef } from "react"; import { useCardBorderHidden } from "components/Pages/useCardBorderHidden"; import { PostContent, Block } from "../PostContent"; import { PubLeafletBlocksHeader, PubLeafletBlocksText, - PubLeafletComment, PubLeafletPagesLinearDocument, PubLeafletPagesCanvas, PubLeafletPublication, @@ -18,10 +17,9 @@ import type { StandardSitePostData } from "app/api/rpc/[command]/get_standard_si import { TextBlock } from "./TextBlock"; import { useDocument } from "contexts/DocumentContext"; import { openPage, useOpenPages } from "../postPageState"; +import { openInteractionDrawer } from "../Interactions/Interactions"; import { CommentTiny } from "components/Icons/CommentTiny"; import { CanvasBackgroundPattern } from "components/Canvas"; -import { DiscussionModal } from "components/DiscussionModal"; -import { getDocumentURL } from "app/(app)/lish/createPub/getPublicationURL"; export function PublishedPageLinkBlock(props: { blocks: PubLeafletPagesLinearDocument.Block[] | PubLeafletPagesCanvas.Block[]; @@ -206,51 +204,37 @@ export function PagePreview(props: { const Interactions = (props: { pageId: string; parentPageId?: string }) => { const { uri: document_uri, - commentsCount: comments, + commentsCountByPage, mentions, - normalizedDocument, - normalizedPublication, } = useDocument(); + let comments = commentsCountByPage[props.pageId] ?? 0; let quotes = mentions.filter((q) => q.link.includes(props.pageId)).length; - let [discussionsOpen, setDiscussionsOpen] = useState(false); - let postUrl = `${getDocumentURL( - normalizedDocument, - document_uri, - normalizedPublication, - )}?page=${props.pageId}`; + if (quotes + comments === 0) return null; return (
- {quotes + comments > 0 && ( - <> - - - - )} +
); }; diff --git a/app/(app)/lish/[did]/[publication]/[rkey]/CanvasPage.tsx b/app/(app)/lish/[did]/[publication]/[rkey]/CanvasPage.tsx index be10764a..9a49c0b5 100644 --- a/app/(app)/lish/[did]/[publication]/[rkey]/CanvasPage.tsx +++ b/app/(app)/lish/[did]/[publication]/[rkey]/CanvasPage.tsx @@ -68,7 +68,7 @@ export function CanvasPage({ data={document} profile={profile} preferences={preferences} - commentsCount={document.commentsCount} + commentsCount={document.commentsCountByPage[pageId ?? ""] ?? 0} quotesCount={getQuoteCount(document.quotesAndMentions, pageId)} recommendsCount={document.recommendsCount} /> diff --git a/app/(app)/lish/[did]/[publication]/[rkey]/Interactions/InteractionDrawer.tsx b/app/(app)/lish/[did]/[publication]/[rkey]/Interactions/InteractionDrawer.tsx index 13cf1a60..b2d4b376 100644 --- a/app/(app)/lish/[did]/[publication]/[rkey]/Interactions/InteractionDrawer.tsx +++ b/app/(app)/lish/[did]/[publication]/[rkey]/Interactions/InteractionDrawer.tsx @@ -90,7 +90,8 @@ const InteractionDrawerContent = (props: { let drawer = useDrawerOpen(props.document_uri); if (!drawer) return null; - let { commentsCount } = useDocument(); + let { commentsCountByPage } = useDocument(); + let commentsCount = commentsCountByPage[props.pageId ?? ""] ?? 0; let { threadStack } = useInteractionState(props.document_uri); const drawerNav = useMemo( () => ({ diff --git a/app/(app)/lish/[did]/[publication]/[rkey]/Interactions/useDocumentDiscussionData.ts b/app/(app)/lish/[did]/[publication]/[rkey]/Interactions/useDocumentDiscussionData.ts index 1299b0be..a3b90067 100644 --- a/app/(app)/lish/[did]/[publication]/[rkey]/Interactions/useDocumentDiscussionData.ts +++ b/app/(app)/lish/[did]/[publication]/[rkey]/Interactions/useDocumentDiscussionData.ts @@ -41,6 +41,12 @@ export function useDocumentDiscussionData( const documentRecord = data?.document ?? null; const pages = documentRecord ? (getDocumentPages(documentRecord) ?? []) : []; + const commentsCountByPage: Record = {}; + for (const c of data?.comments ?? []) { + const onPage = (c.record as { onPage?: string } | null)?.onPage ?? ""; + commentsCountByPage[onPage] = (commentsCountByPage[onPage] ?? 0) + 1; + } + // The drawer content only reads uri / normalizedDocument / normalizedPublication // off the document context; the rest is filled with sensible defaults. const documentContextValue: DocumentContextValue | null = documentRecord @@ -53,6 +59,7 @@ export function useDocumentDiscussionData( quotesAndMentions: data?.quotesAndMentions ?? [], publication: null, commentsCount: data?.comments.length ?? 0, + commentsCountByPage, mentions: [], leafletId: null, recommendsCount: 0, diff --git a/app/(app)/lish/[did]/[publication]/[rkey]/LinearDocumentPage.tsx b/app/(app)/lish/[did]/[publication]/[rkey]/LinearDocumentPage.tsx index 94db6908..89ad50d0 100644 --- a/app/(app)/lish/[did]/[publication]/[rkey]/LinearDocumentPage.tsx +++ b/app/(app)/lish/[did]/[publication]/[rkey]/LinearDocumentPage.tsx @@ -103,7 +103,7 @@ export function LinearDocumentPage({ showComments={preferences.showComments !== false} showMentions={preferences.showMentions !== false} showRecommends={preferences.showRecommends !== false} - commentsCount={document.commentsCount} + commentsCount={document.commentsCountByPage[pageId ?? ""] ?? 0} quotesCount={getQuoteCount(document.quotesAndMentions, pageId) || 0} recommendsCount={document.recommendsCount} /> diff --git a/app/(app)/lish/[did]/[publication]/[rkey]/PostHeader/PostHeader.tsx b/app/(app)/lish/[did]/[publication]/[rkey]/PostHeader/PostHeader.tsx index 72cd56b7..2610afb2 100644 --- a/app/(app)/lish/[did]/[publication]/[rkey]/PostHeader/PostHeader.tsx +++ b/app/(app)/lish/[did]/[publication]/[rkey]/PostHeader/PostHeader.tsx @@ -96,7 +96,7 @@ export function PostHeader(props: { quotesCount={ getQuoteCount(document?.quotesAndMentions || []) || 0 } - commentsCount={document?.commentsCount || 0} + commentsCount={document?.commentsCountByPage[""] || 0} recommendsCount={document?.recommendsCount || 0} /> )} diff --git a/app/(app)/lish/[did]/[publication]/[rkey]/PublicationPageRenderer.tsx b/app/(app)/lish/[did]/[publication]/[rkey]/PublicationPageRenderer.tsx index d4d77b0e..02ad3b3b 100644 --- a/app/(app)/lish/[did]/[publication]/[rkey]/PublicationPageRenderer.tsx +++ b/app/(app)/lish/[did]/[publication]/[rkey]/PublicationPageRenderer.tsx @@ -150,6 +150,7 @@ export async function PublicationPageRenderer({ pages: (publication.publication_pages ?? []).filter((p) => p.record_uri), }, commentsCount: 0, + commentsCountByPage: {}, mentions: [], leafletId: null, recommendsCount: 0, diff --git a/app/(app)/lish/[did]/[publication]/[rkey]/getPostPageData.ts b/app/(app)/lish/[did]/[publication]/[rkey]/getPostPageData.ts index e5d45190..67a468ff 100644 --- a/app/(app)/lish/[did]/[publication]/[rkey]/getPostPageData.ts +++ b/app/(app)/lish/[did]/[publication]/[rkey]/getPostPageData.ts @@ -5,7 +5,11 @@ import { normalizePublicationRecord, } from "src/utils/normalizeRecords"; import { resolvePublicationTheme } from "lexicons/src/normalize"; -import { PubLeafletPublication, SiteStandardPublication } from "lexicons/api"; +import { + PubLeafletComment, + PubLeafletPublication, + SiteStandardPublication, +} from "lexicons/api"; import { documentUriFilter } from "src/utils/uriHelpers"; import { getDocumentURL } from "app/(app)/lish/createPub/getPublicationURL"; @@ -16,7 +20,7 @@ export async function getPostPageData(did: string, rkey: string) { ` data, uri, - comments_on_documents(count), + comments_on_documents(record), documents_in_publications(publications(*, documents_in_publications(documents(uri, data)), publication_subscriptions(*), @@ -150,7 +154,17 @@ export async function getPostPageData(did: string, rkey: string) { } : null; const recommendsCount = document.recommends_on_documents?.[0]?.count ?? 0; - const commentsCount = document.comments_on_documents?.[0]?.count ?? 0; + + // Comments are counted per-page so subpages (and the main page) each show only + // their own discussion. Comments on the main page have no `onPage`, so they're + // keyed under "". `commentsCount` remains the document-wide total. + const commentRecords = document.comments_on_documents ?? []; + const commentsCountByPage: Record = {}; + for (const c of commentRecords) { + const onPage = (c.record as PubLeafletComment.Record)?.onPage ?? ""; + commentsCountByPage[onPage] = (commentsCountByPage[onPage] ?? 0) + 1; + } + const commentsCount = commentRecords.length; return { ...document, @@ -163,6 +177,7 @@ export async function getPostPageData(did: string, rkey: string) { // Explicit relational data for DocumentContext publication, commentsCount, + commentsCountByPage, mentions: document.document_mentions_in_bsky, leafletId: document.leaflets_in_publications[0]?.leaflet || null, // Recommends data diff --git a/app/(app)/lish/[did]/[publication]/theme-settings/PostPreview.tsx b/app/(app)/lish/[did]/[publication]/theme-settings/PostPreview.tsx index 8513243a..a146ec64 100644 --- a/app/(app)/lish/[did]/[publication]/theme-settings/PostPreview.tsx +++ b/app/(app)/lish/[did]/[publication]/theme-settings/PostPreview.tsx @@ -48,6 +48,7 @@ function makeFakeDocument( prevNext: undefined, publication: publication || null, commentsCount: 0, + commentsCountByPage: {}, comments_on_documents: [], mentions: [], document_mentions_in_bsky: [], @@ -111,6 +112,7 @@ export function PostPreview(props: { quotesAndMentions: [], publication: pubInfo, commentsCount: 0, + commentsCountByPage: {}, mentions: [], leafletId: null, recommendsCount: 0, diff --git a/contexts/DocumentContext.tsx b/contexts/DocumentContext.tsx index 3271542b..89a9f62e 100644 --- a/contexts/DocumentContext.tsx +++ b/contexts/DocumentContext.tsx @@ -18,6 +18,7 @@ export type DocumentContextValue = Pick< | "quotesAndMentions" | "publication" | "commentsCount" + | "commentsCountByPage" | "mentions" | "leafletId" | "recommendsCount"