From ae320a886d952a275da5379a2b6d0b8a6afc8c40 Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Thu, 4 Sep 2025 20:39:17 +0900 Subject: [PATCH] simplify active highlight rendering to support comments --- .../[rkey]/Interactions/Quotes.tsx | 3 +-- .../[publication]/[rkey]/useHighlight.tsx | 21 +++++++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/lish/[did]/[publication]/[rkey]/Interactions/Quotes.tsx b/app/lish/[did]/[publication]/[rkey]/Interactions/Quotes.tsx index 77f8686b..2cc134c7 100644 --- a/app/lish/[did]/[publication]/[rkey]/Interactions/Quotes.tsx +++ b/app/lish/[did]/[publication]/[rkey]/Interactions/Quotes.tsx @@ -95,7 +95,7 @@ export const QuoteContent = (props: { useActiveHighlightState.setState({ activeHighlight: null }); }} onMouseEnter={() => { - useActiveHighlightState.setState({ activeHighlight: props.index }); + useActiveHighlightState.setState({ activeHighlight: props.position }); }} >
{ const blockPath = [...currentPath, index]; - console.log(blockPath); // Handle different block types if (PubLeafletBlocksUnorderedList.isMain(block.block)) { diff --git a/app/lish/[did]/[publication]/[rkey]/useHighlight.tsx b/app/lish/[did]/[publication]/[rkey]/useHighlight.tsx index efe62578..7c8b0951 100644 --- a/app/lish/[did]/[publication]/[rkey]/useHighlight.tsx +++ b/app/lish/[did]/[publication]/[rkey]/useHighlight.tsx @@ -1,14 +1,14 @@ // Generated w/ Claude 4 "use client"; -import { useParams, useSearchParams } from "next/navigation"; +import { useParams } from "next/navigation"; import { useContext } from "react"; import { PostPageContext } from "./PostPageContext"; import { create } from "zustand"; -import { decodeQuotePosition } from "./quotePosition"; +import { decodeQuotePosition, QuotePosition } from "./quotePosition"; export const useActiveHighlightState = create(() => ({ - activeHighlight: null as null | number, + activeHighlight: null as null | QuotePosition, })); export const useHighlight = (pos: number[]) => { @@ -17,17 +17,12 @@ export const useHighlight = (pos: number[]) => { let activeHighlight = useActiveHighlightState( (state) => state.activeHighlight, ); - let highlights = - doc?.document_mentions_in_bsky - .filter((m, i) => i === activeHighlight) - .map((mention) => { - return new URL(mention.link).pathname.split("/l-quote/")[1]; - }) - .filter((s) => s !== null) || []; - if (quote) highlights.push(quote as string); + let highlights = activeHighlight ? [activeHighlight] : []; + let decodedQuote = quote ? decodeQuotePosition(quote as string) : null; + if (decodedQuote) highlights.push(decodedQuote); + console.log(highlights); return highlights - .map((highlight) => { - let quotePosition = decodeQuotePosition(highlight); + .map((quotePosition) => { if (!quotePosition) return null; let maxLength = Math.max( quotePosition.start.block.length, -- 2.51.2