mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix: resolve publication details visibility, comment re-render performance, and translation issues
- fix(challenge-modal): restore publication details for text/image challenges - fix(comment-content): optimize Zustand selector to prevent excessive re-renders - fix(translations): translate search_ops_placeholder key across all locales
This commit is contained in:
@@ -328,6 +328,24 @@ const Challenge = ({ challenge, closeModal }: ChallengeProps) => {
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<div className={styles.name}>
|
||||
<input type='text' value={displayName || capitalize(t('anonymous'))} disabled />
|
||||
</div>
|
||||
{title && (
|
||||
<div className={styles.subject}>
|
||||
<input type='text' value={title} disabled />
|
||||
</div>
|
||||
)}
|
||||
{content && (
|
||||
<div className={styles.content}>
|
||||
<textarea value={content} disabled cols={48} rows={4} wrap='soft' />
|
||||
</div>
|
||||
)}
|
||||
{link && (
|
||||
<div className={styles.link}>
|
||||
<input type='text' value={link} disabled />
|
||||
</div>
|
||||
)}
|
||||
<div className={styles.challengeContainer}>
|
||||
<input
|
||||
ref={inputRef}
|
||||
|
||||
@@ -36,20 +36,26 @@ const useScopedCidToNumber = (cids: string[]) => {
|
||||
return [...uniqueCids].sort();
|
||||
}, [cids]);
|
||||
|
||||
const cidToNumber = usePostNumberStore((s) => s.cidToNumber);
|
||||
const cidToNumber = usePostNumberStore(
|
||||
useMemo(
|
||||
() => (state) => {
|
||||
if (sortedUniqueCids.length === 0) {
|
||||
return {} as Record<string, number>;
|
||||
}
|
||||
const nextCidToNumber: Record<string, number> = {};
|
||||
for (const cid of sortedUniqueCids) {
|
||||
const number = state.cidToNumber[cid];
|
||||
if (typeof number === 'number') {
|
||||
nextCidToNumber[cid] = number;
|
||||
}
|
||||
}
|
||||
return nextCidToNumber;
|
||||
},
|
||||
[sortedUniqueCids],
|
||||
),
|
||||
);
|
||||
|
||||
if (sortedUniqueCids.length === 0) {
|
||||
return {} as Record<string, number>;
|
||||
}
|
||||
|
||||
const nextCidToNumber: Record<string, number> = {};
|
||||
for (const cid of sortedUniqueCids) {
|
||||
const number = cidToNumber[cid];
|
||||
if (typeof number === 'number') {
|
||||
nextCidToNumber[cid] = number;
|
||||
}
|
||||
}
|
||||
return nextCidToNumber;
|
||||
return cidToNumber;
|
||||
};
|
||||
|
||||
const CommentContent = ({ comment: post }: { comment: Comment }) => {
|
||||
@@ -80,23 +86,27 @@ const CommentContent = ({ comment: post }: { comment: Comment }) => {
|
||||
const isReply = !!parentCid;
|
||||
const isReplyingToReply = isReply && parentCid !== postCid;
|
||||
|
||||
const contentNumbers = !content ? new Set<number>() : new Set([...content.matchAll(/(?<![>/\w])>>(\d+)(?![\d/])/g)].map((m) => parseInt(m[1], 10)));
|
||||
const contentNumbers = useMemo(() => {
|
||||
if (!content) return new Set<number>();
|
||||
return new Set([...content.matchAll(/(?<![>/\w])>>(\d+)(?![\d/])/g)].map((m) => parseInt(m[1], 10)));
|
||||
}, [content]);
|
||||
|
||||
const relevantQuotedCids = (() => {
|
||||
const relevantQuotedCids = useMemo(() => {
|
||||
const cids = quotedCids ? [...quotedCids] : [];
|
||||
if (parentCid) {
|
||||
cids.push(parentCid);
|
||||
}
|
||||
return cids;
|
||||
})();
|
||||
}, [quotedCids, parentCid]);
|
||||
|
||||
const cidToNumber = useScopedCidToNumber(relevantQuotedCids);
|
||||
const filteredQuotedCids = !quotedCids?.length
|
||||
? []
|
||||
: quotedCids.filter((cid: string) => {
|
||||
const num = cidToNumber[cid];
|
||||
return num === undefined || !contentNumbers.has(num);
|
||||
});
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user