fix(post): render OP backlinks from replies quoting OP

This commit is contained in:
plebeius
2026-02-11 18:52:10 +08:00
parent 716c782d1a
commit d862550132
3 changed files with 15 additions and 33 deletions
+7 -15
View File
@@ -76,7 +76,6 @@ const PostInfo = ({
onApprove, onApprove,
onReject, onReject,
quotedByMap, quotedByMap,
cidToReply,
}: PostProps) => { }: PostProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const { author, cid, deleted, locked, pinned, parentCid, postCid, reason, removed, state, subplebbitAddress, timestamp } = post || {}; const { author, cid, deleted, locked, pinned, parentCid, postCid, reason, removed, state, subplebbitAddress, timestamp } = post || {};
@@ -442,11 +441,12 @@ const PostInfo = ({
{cid && {cid &&
!parentCid && !parentCid &&
isInPostPageView && isInPostPageView &&
cidToReply && quotedByMap
[...new Set<string>((post?.quotedCids || []) as string[])].map((quotedCid) => { ?.get(cid)
const reply = cidToReply.get(quotedCid); ?.map(
return reply?.cid && !(reply.deleted || reply.removed) && <ReplyQuotePreview key={`op-bl-${reply.cid}`} isBacklinkReply={true} backlinkReply={reply} />; (reply: Comment) =>
})} reply?.cid && !(reply?.deleted || reply?.removed) && <ReplyQuotePreview key={`op-bl-${reply.cid}`} isBacklinkReply={true} backlinkReply={reply} />,
)}
</span> </span>
</div> </div>
); );
@@ -690,14 +690,6 @@ const PostDesktop = ({
return map; return map;
}, [filteredReplies, numberToCid]); }, [filteredReplies, numberToCid]);
const cidToReply = useMemo(() => {
const map = new Map<string, Comment>();
for (const reply of filteredReplies) {
if (reply.cid) map.set(reply.cid, reply);
}
return map;
}, [filteredReplies]);
// Virtuoso scroll position management for infinite replies // Virtuoso scroll position management for infinite replies
const virtuosoRef = useRef<VirtuosoHandle | null>(null); const virtuosoRef = useRef<VirtuosoHandle | null>(null);
const virtuosoStateKey = `replies-desktop-${cid}`; const virtuosoStateKey = `replies-desktop-${cid}`;
@@ -786,7 +778,7 @@ const PostDesktop = ({
isPublishing={isPublishing} isPublishing={isPublishing}
onApprove={onApprove} onApprove={onApprove}
onReject={onReject} onReject={onReject}
cidToReply={cidToReply} quotedByMap={quotedByMap}
/> />
{!isHidden && !content && !(deleted || removed) && <div className={styles.spacer} />} {!isHidden && !content && !(deleted || removed) && <div className={styles.spacer} />}
{!isHidden && <CommentContent comment={post} />} {!isHidden && <CommentContent comment={post} />}
+8 -17
View File
@@ -380,7 +380,7 @@ const PostMediaContent = ({ post, link }: { post: any; link: string }) => {
); );
}; };
const ReplyBacklinks = ({ post, quotedByMap, cidToReply, isInPostPageView }: PostProps) => { const ReplyBacklinks = ({ post, quotedByMap, isInPostPageView }: PostProps) => {
const { cid, parentCid } = post || {}; const { cid, parentCid } = post || {};
const { replies } = useReplies({ comment: post, flat: true, accountComments: { newerThan: Infinity } }); const { replies } = useReplies({ comment: post, flat: true, accountComments: { newerThan: Infinity } });
@@ -388,13 +388,12 @@ const ReplyBacklinks = ({ post, quotedByMap, cidToReply, isInPostPageView }: Pos
cid && cid &&
!parentCid && !parentCid &&
isInPostPageView && isInPostPageView &&
cidToReply && quotedByMap
post?.quotedCids?.length && ?.get(cid)
[...new Set<string>(post.quotedCids as string[])] ?.map(
.map((quotedCid) => { (reply: Comment) =>
const reply = cidToReply.get(quotedCid); reply?.cid && !(reply?.deleted || reply?.removed) && <ReplyQuotePreview key={`op-bl-${reply.cid}`} isBacklinkReply={true} backlinkReply={reply} />,
return reply?.cid && !(reply.deleted || reply.removed) && <ReplyQuotePreview key={`op-bl-${reply.cid}`} isBacklinkReply={true} backlinkReply={reply} />; )
})
.filter(Boolean); .filter(Boolean);
const replyBacklinks = cid && parentCid && ((replies?.length || 0) > 0 || quotedByMap?.get(cid)?.length) && ( const replyBacklinks = cid && parentCid && ((replies?.length || 0) > 0 || quotedByMap?.get(cid)?.length) && (
@@ -534,14 +533,6 @@ const PostMobile = ({
return map; return map;
}, [filteredReplies, numberToCid]); }, [filteredReplies, numberToCid]);
const cidToReply = useMemo(() => {
const map = new Map<string, Comment>();
for (const reply of filteredReplies) {
if (reply.cid) map.set(reply.cid, reply);
}
return map;
}, [filteredReplies]);
// Virtuoso scroll position management for infinite replies // Virtuoso scroll position management for infinite replies
const virtuosoRef = useRef<VirtuosoHandle | null>(null); const virtuosoRef = useRef<VirtuosoHandle | null>(null);
const virtuosoStateKey = `replies-mobile-${cid}`; const virtuosoStateKey = `replies-mobile-${cid}`;
@@ -610,7 +601,7 @@ const PostMobile = ({
{shouldShowSnow() && <img src='assets/xmashat.gif' className={styles.xmasHat} alt='' />} {shouldShowSnow() && <img src='assets/xmashat.gif' className={styles.xmasHat} alt='' />}
<PostInfoAndMedia post={post} postReplyCount={replyCount} roles={roles} threadNumber={post?.number} /> <PostInfoAndMedia post={post} postReplyCount={replyCount} roles={roles} threadNumber={post?.number} />
<CommentContent comment={post} /> <CommentContent comment={post} />
<ReplyBacklinks post={post} quotedByMap={quotedByMap} cidToReply={cidToReply} isInPostPageView={isInPostView} /> <ReplyBacklinks post={post} quotedByMap={quotedByMap} isInPostPageView={isInPostView} />
</div> </div>
{!isInPostView && !isInPendingPostView && (showReplies || isModQueue) && ( {!isInPostView && !isInPendingPostView && (showReplies || isModQueue) && (
<div className={styles.postLink}> <div className={styles.postLink}>
-1
View File
@@ -32,7 +32,6 @@ export interface PostProps {
onApprove?: () => void; onApprove?: () => void;
onReject?: () => void; onReject?: () => void;
quotedByMap?: Map<string, Comment[]>; quotedByMap?: Map<string, Comment[]>;
cidToReply?: Map<string, Comment>;
isInPostPageView?: boolean; isInPostPageView?: boolean;
} }