mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix pending reply logic, add it to board
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
function renderComments(comments) {
|
||||
let displayedCount = 0;
|
||||
let omittedCount = 0;
|
||||
|
||||
const renderComment = (comment) => {
|
||||
const { replyCount, replies: { pages: { topAll: { comments: nestedComments = [] } = {} } = {} } = {} } = comment;
|
||||
let renderedNestedComments = [];
|
||||
|
||||
if (replyCount > 0 && nestedComments.length > 0) {
|
||||
const result = renderComments(nestedComments);
|
||||
renderedNestedComments = result.renderedComments;
|
||||
omittedCount += result.omittedCount;
|
||||
}
|
||||
|
||||
const allComments = [comment, ...renderedNestedComments];
|
||||
const displayedComments = allComments.slice(0, 5 - displayedCount);
|
||||
|
||||
displayedCount += displayedComments.length;
|
||||
omittedCount += allComments.length - displayedComments.length;
|
||||
|
||||
return displayedComments;
|
||||
};
|
||||
|
||||
const renderedComments = comments?.flatMap(renderComment);
|
||||
renderedComments?.sort((a, b) => a.timestamp - b.timestamp);
|
||||
|
||||
return { renderedComments, omittedCount };
|
||||
}
|
||||
|
||||
export default renderComments;
|
||||
@@ -1,24 +0,0 @@
|
||||
function renderThreadComments(comment, pendingComment = null) {
|
||||
const nestedComments = comment?.replies?.pages?.topAll?.comments || {};
|
||||
const commentKeys = Object.keys(nestedComments);
|
||||
|
||||
const renderedComments = commentKeys.map(key => {
|
||||
const comment = nestedComments[key];
|
||||
const { replies: { pages: { topAll: { comments: childNestedComments = [] } = {} } = {} } = {} } = comment;
|
||||
if (comment.replyCount > 0 && childNestedComments) {
|
||||
const renderedNestedComments = renderThreadComments(comment);
|
||||
return [comment, ...renderedNestedComments];
|
||||
}
|
||||
return [comment];
|
||||
}).flat();
|
||||
|
||||
const sortedComments = renderedComments.sort((a, b) => a.timestamp - b.timestamp);
|
||||
|
||||
if (pendingComment?.parentCid === comment?.cid) {
|
||||
sortedComments.push(pendingComment);
|
||||
}
|
||||
|
||||
return sortedComments;
|
||||
}
|
||||
|
||||
export default renderThreadComments;
|
||||
Reference in New Issue
Block a user