mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(quotes): scope post-number lookup by subplebbit, OP quote always navigates to thread
- numberToCid scoped by subplebbit address to fix wrong preview in /all/ - OP quote click navigates to thread page instead of highlighting card
This commit is contained in:
@@ -147,7 +147,7 @@ const CommentContent = ({ comment: post }: { comment: Comment }) => {
|
||||
)
|
||||
) : (
|
||||
<>
|
||||
{!showOriginal && <Markdown content={displayContent} postCid={postCid} />}
|
||||
{!showOriginal && <Markdown content={displayContent} postCid={postCid} subplebbitAddress={subplebbitAddress} />}
|
||||
{pendingApproval && (
|
||||
<>
|
||||
<br />
|
||||
@@ -182,7 +182,7 @@ const CommentContent = ({ comment: post }: { comment: Comment }) => {
|
||||
)}
|
||||
{edit && original?.content !== content && (
|
||||
<span className={styles.editedInfo}>
|
||||
{showOriginal && <Markdown content={original?.content} postCid={postCid} />}
|
||||
{showOriginal && <Markdown content={original?.content} postCid={postCid} subplebbitAddress={subplebbitAddress} />}
|
||||
<br />
|
||||
<br />
|
||||
<Trans
|
||||
|
||||
@@ -186,12 +186,13 @@ interface MarkdownProps {
|
||||
content: string;
|
||||
title?: string;
|
||||
postCid?: string;
|
||||
subplebbitAddress?: string;
|
||||
}
|
||||
|
||||
const NUMBER_QUOTE_HREF_REGEX = /^#q-(\d+)$/;
|
||||
|
||||
const NumberQuoteLink = ({ number, threadPostCid }: { number: number; threadPostCid?: string }) => {
|
||||
const cid = usePostNumberStore((state) => state.numberToCid[number]);
|
||||
const NumberQuoteLink = ({ number, threadPostCid, subplebbitAddress }: { number: number; threadPostCid?: string; subplebbitAddress?: string }) => {
|
||||
const cid = usePostNumberStore((state) => (subplebbitAddress ? state.numberToCid[subplebbitAddress]?.[number] : undefined));
|
||||
const commentFromStore = useSubplebbitsPagesStore((state) => (cid ? state.comments[cid] : undefined));
|
||||
const commentFromHook = useComment({ commentCid: cid, onlyIfCached: true });
|
||||
const comment = commentFromHook?.number !== undefined ? commentFromHook : commentFromStore;
|
||||
@@ -204,7 +205,7 @@ const NumberQuoteLink = ({ number, threadPostCid }: { number: number; threadPost
|
||||
return <ReplyQuotePreview isQuotelinkReply={true} quotelinkReply={comment} isOP={isOP} showTrailingBreak={false} />;
|
||||
};
|
||||
|
||||
const renderAnchorLink = (children: React.ReactNode, href: string, threadPostCid?: string) => {
|
||||
const renderAnchorLink = (children: React.ReactNode, href: string, threadPostCid?: string, subplebbitAddress?: string) => {
|
||||
if (!href) {
|
||||
return <span>{children}</span>;
|
||||
}
|
||||
@@ -214,7 +215,7 @@ const renderAnchorLink = (children: React.ReactNode, href: string, threadPostCid
|
||||
const number = parseInt(numberQuoteMatch[1], 10);
|
||||
return (
|
||||
<span className={styles.inlineQuoteLink}>
|
||||
<NumberQuoteLink number={number} threadPostCid={threadPostCid} />
|
||||
<NumberQuoteLink number={number} threadPostCid={threadPostCid} subplebbitAddress={subplebbitAddress} />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -268,7 +269,7 @@ const renderAnchorLink = (children: React.ReactNode, href: string, threadPostCid
|
||||
);
|
||||
};
|
||||
|
||||
const Markdown = ({ content, title, postCid }: MarkdownProps) => {
|
||||
const Markdown = ({ content, title, postCid, subplebbitAddress }: MarkdownProps) => {
|
||||
const remarkPlugins = useMemo(() => {
|
||||
const plugins: any[] = [[supersub]];
|
||||
|
||||
@@ -338,13 +339,13 @@ const Markdown = ({ content, title, postCid }: MarkdownProps) => {
|
||||
console.debug('Invalid URL:', href);
|
||||
}
|
||||
|
||||
return renderAnchorLink(children, href, postCid);
|
||||
return renderAnchorLink(children, href, postCid, subplebbitAddress);
|
||||
}
|
||||
|
||||
return renderAnchorLink(children, href || '', postCid);
|
||||
return renderAnchorLink(children, href || '', postCid, subplebbitAddress);
|
||||
},
|
||||
}) as ExtendedComponents,
|
||||
[isInCatalogView, postCid],
|
||||
[isInCatalogView, postCid, subplebbitAddress],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -849,7 +849,7 @@ const PostDesktop = ({
|
||||
return map;
|
||||
})();
|
||||
|
||||
const quotedByMap = useQuotedByMap(filteredReplies);
|
||||
const quotedByMap = useQuotedByMap(filteredReplies, subplebbitAddress);
|
||||
|
||||
const visibleReplies = useProgressiveRender(filteredReplies, {
|
||||
batchSize: 50,
|
||||
|
||||
@@ -606,7 +606,7 @@ const PostMobile = ({
|
||||
return map;
|
||||
})();
|
||||
|
||||
const quotedByMap = useQuotedByMap(filteredReplies);
|
||||
const quotedByMap = useQuotedByMap(filteredReplies, subplebbitAddress);
|
||||
|
||||
const visibleReplies = useProgressiveRender(filteredReplies, {
|
||||
batchSize: 50,
|
||||
|
||||
@@ -131,8 +131,12 @@ const DesktopQuotePreview = ({ backlinkReply, quotelinkReply, isBacklinkReply, i
|
||||
if (cid && subplebbitAddress) {
|
||||
const boardPath = getBoardPath(subplebbitAddress, directories);
|
||||
const threadRoute = `/${boardPath}/thread/${cid}`;
|
||||
if (isOpQuote && location.pathname === threadRoute) {
|
||||
scrollToThreadCardTop(cid);
|
||||
if (isOpQuote) {
|
||||
if (location.pathname === threadRoute) {
|
||||
scrollToThreadCardTop(cid);
|
||||
} else {
|
||||
navigate(threadRoute);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (scrollToReplyOnPage(cid)) return;
|
||||
@@ -248,8 +252,12 @@ const MobileQuotePreview = ({ backlinkReply, quotelinkReply, isBacklinkReply, is
|
||||
if (cid && subplebbitAddress) {
|
||||
const boardPath = getBoardPath(subplebbitAddress, directories);
|
||||
const threadRoute = `/${boardPath}/thread/${cid}`;
|
||||
if (isOpQuote && location.pathname === threadRoute) {
|
||||
scrollToThreadCardTop(cid);
|
||||
if (isOpQuote) {
|
||||
if (location.pathname === threadRoute) {
|
||||
scrollToThreadCardTop(cid);
|
||||
} else {
|
||||
navigate(threadRoute);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (scrollToReplyOnPage(cid)) return;
|
||||
|
||||
Reference in New Issue
Block a user