mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix: show OP badge for number-based quote links
`NumberQuoteLink` now receives thread context from `Markdown` and forwards `isOP` to `ReplyQuotePreview` when the resolved quote CID matches the thread `postCid`. This makes `>>14` render as `>>14 (OP)` consistently with existing `quotedCids` links.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { Fragment, useState } from 'react';
|
||||
import { Fragment, useMemo, useState } from 'react';
|
||||
import { useLocation, useParams } from 'react-router-dom';
|
||||
import { Trans, useTranslation } from 'react-i18next';
|
||||
import { Comment, useComment } from '@plebbit/plebbit-react-hooks';
|
||||
import useSubplebbitsPagesStore from '@plebbit/plebbit-react-hooks/dist/stores/subplebbits-pages';
|
||||
import usePostNumberStore from '../../stores/use-post-number-store';
|
||||
import Plebbit from '@plebbit/plebbit-js';
|
||||
import { getFormattedDate, getFormattedTimeAgo } from '../../lib/utils/time-utils';
|
||||
import { isPostPageView } from '../../lib/utils/view-utils';
|
||||
@@ -52,6 +53,23 @@ const CommentContent = ({ comment: post }: { comment: Comment }) => {
|
||||
const isReply = !!parentCid;
|
||||
const isReplyingToReply = isReply && parentCid !== postCid;
|
||||
|
||||
const contentNumbers = useMemo(() => {
|
||||
if (!content) return new Set<number>();
|
||||
const matches = content.matchAll(/(?<![>/\w])>>(\d+)(?![\d/])/g);
|
||||
return new Set([...matches].map((m) => parseInt(m[1], 10)));
|
||||
}, [content]);
|
||||
|
||||
const cidToNumber = usePostNumberStore((state) => state.cidToNumber);
|
||||
const filteredQuotedCids = useMemo(() => {
|
||||
if (!quotedCids?.length) return [];
|
||||
return quotedCids.filter((cid: string) => {
|
||||
const num = cidToNumber[cid];
|
||||
return num === undefined || !contentNumbers.has(num);
|
||||
});
|
||||
}, [quotedCids, cidToNumber, contentNumbers]);
|
||||
|
||||
const shouldShowReplyingToReply = isReplyingToReply && (parentCid ? !contentNumbers.has(cidToNumber[parentCid] ?? -1) : true);
|
||||
|
||||
const stateString = useStateString(post);
|
||||
|
||||
const loadingString = <div className={styles.stateString}>{stateString !== 'Failed' ? <LoadingEllipsis string={stateString || t('loading')} /> : stateString}</div>;
|
||||
@@ -61,9 +79,9 @@ const CommentContent = ({ comment: post }: { comment: Comment }) => {
|
||||
{isReply &&
|
||||
state !== 'failed' &&
|
||||
!(deleted || removed) &&
|
||||
(quotedCids?.length > 0
|
||||
? quotedCids.map((cid: string) => <QuotedCidLink key={cid} cid={cid} postCid={postCid} />)
|
||||
: isReplyingToReply && <ReplyQuotePreview isQuotelinkReply={true} quotelinkReply={quotelinkReply} />)}
|
||||
(filteredQuotedCids.length > 0
|
||||
? filteredQuotedCids.map((cid: string) => <QuotedCidLink key={cid} cid={cid} postCid={postCid} />)
|
||||
: shouldShowReplyingToReply && <ReplyQuotePreview isQuotelinkReply={true} quotelinkReply={quotelinkReply} />)}
|
||||
{removed ? (
|
||||
reason ? (
|
||||
<>
|
||||
@@ -86,7 +104,7 @@ const CommentContent = ({ comment: post }: { comment: Comment }) => {
|
||||
)
|
||||
) : (
|
||||
<>
|
||||
{!showOriginal && <Markdown content={displayContent} />}
|
||||
{!showOriginal && <Markdown content={displayContent} postCid={postCid} />}
|
||||
{pendingApproval && (
|
||||
<>
|
||||
<br />
|
||||
@@ -102,7 +120,7 @@ const CommentContent = ({ comment: post }: { comment: Comment }) => {
|
||||
)}
|
||||
{edit && original?.content !== content && (
|
||||
<span className={styles.editedInfo}>
|
||||
{showOriginal && <Markdown content={original?.content} />}
|
||||
{showOriginal && <Markdown content={original?.content} postCid={postCid} />}
|
||||
<br />
|
||||
<br />
|
||||
<Trans
|
||||
|
||||
Reference in New Issue
Block a user