Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion components/drops/view/part/DropPartMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export interface DropPartMarkdownProps {
readonly onQuoteClick: (drop: ApiDrop) => void;
readonly textSize?: "sm" | "md";
readonly currentDropId?: string;
readonly currentSerialNo?: number;
}

function DropPartMarkdown({
Expand All @@ -225,6 +226,7 @@ function DropPartMarkdown({
onQuoteClick,
textSize,
currentDropId,
currentSerialNo,
}: DropPartMarkdownProps) {
const isMobile = useIsMobileScreen();
const { emojiMap, findNativeEmoji } = useEmoji();
Expand All @@ -243,8 +245,9 @@ function DropPartMarkdown({
createLinkRenderer({
onQuoteClick,
currentDropId,
currentSerialNo,
}),
[onQuoteClick, currentDropId]
[onQuoteClick, currentDropId, currentSerialNo]
);

const { customRenderer, renderParagraph, processContent } = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function areEqual(
"partContent",
"textSize",
"currentDropId",
"currentSerialNo",
];

for (const key of propsToCheck) {
Expand Down
16 changes: 13 additions & 3 deletions components/drops/view/part/dropPartMarkdown/handlers/seize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { renderSeizeQuote } from "../renderers";
interface CreateSeizeHandlersConfig {
readonly onQuoteClick: (drop: ApiDrop) => void;
readonly currentDropId?: string;
readonly currentSerialNo?: number;
}

const ensureSeizeQuote = (href: string): SeizeQuoteLinkInfo => {
Expand All @@ -29,11 +30,19 @@ const ensureSeizeQuote = (href: string): SeizeQuoteLinkInfo => {
};

const createSeizeQuoteHandler = (
onQuoteClick: (drop: ApiDrop) => void
onQuoteClick: (drop: ApiDrop) => void,
currentSerialNo?: number
): LinkHandler => ({
match: (href) => Boolean(parseSeizeQuoteLink(href)),
render: (href) => {
const content = renderSeizeQuote(ensureSeizeQuote(href), onQuoteClick, href);
const quoteInfo = ensureSeizeQuote(href);

// Prevent infinite recursion when a drop references itself by serialNo
if (currentSerialNo && quoteInfo.serialNo && Number.parseInt(quoteInfo.serialNo, 10) === currentSerialNo) {
throw new Error("Seize quote link matches current drop");
}

const content = renderSeizeQuote(quoteInfo, onQuoteClick, href);
if (!content) {
throw new Error("Unable to render seize quote link");
}
Expand Down Expand Up @@ -126,8 +135,9 @@ const createSeizeDropHandler = (currentDropId?: string): LinkHandler =>
export const createSeizeHandlers = ({
onQuoteClick,
currentDropId,
currentSerialNo,
}: CreateSeizeHandlersConfig): LinkHandler[] => [
createSeizeQuoteHandler(onQuoteClick),
createSeizeQuoteHandler(onQuoteClick, currentSerialNo),
createSeizeGroupHandler(),
createSeizeWaveHandler(),
createSeizeDropHandler(currentDropId),
Expand Down
4 changes: 3 additions & 1 deletion components/drops/view/part/dropPartMarkdown/linkHandlers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
interface LinkRendererConfig {
readonly onQuoteClick: (drop: ApiDrop) => void;
readonly currentDropId?: string;
readonly currentSerialNo?: number;
}

interface LinkRenderer {
Expand Down Expand Up @@ -57,8 +58,9 @@ const findMatch = (
export const createLinkRenderer = ({
onQuoteClick,
currentDropId,
currentSerialNo,
}: LinkRendererConfig): LinkRenderer => {
const seizeHandlers = createSeizeHandlers({ onQuoteClick, currentDropId });
const seizeHandlers = createSeizeHandlers({ onQuoteClick, currentDropId, currentSerialNo });
const handlers = createLinkHandlers();

const renderImage: LinkRenderer["renderImage"] = ({ src }) => {
Expand Down
1 change: 1 addition & 0 deletions components/waves/drops/WaveDropPartContentMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const WaveDropPartContentMarkdown: React.FC<
partContent={part.content}
onQuoteClick={onQuoteClick}
currentDropId={drop?.id}
currentSerialNo={drop?.serial_no}
/>
{drop?.updated_at && drop.updated_at !== drop.created_at && (
<div className="tw-text-[10px] tw-leading-none tw-text-iron-500 tw-font-normal tw-mt-0.5">
Expand Down
1 change: 1 addition & 0 deletions components/waves/drops/WaveDropQuote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const WaveDropQuote: React.FC<WaveDropQuoteProps> = ({
textSize="sm"
onQuoteClick={onQuoteClick}
currentDropId={drop?.id}
currentSerialNo={drop?.serial_no}
/>
</div>
</div>
Expand Down