mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
added pending reply to thread
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
function renderThreadComments(comments) {
|
||||
const commentKeys = Object.keys(comments? comments : {});
|
||||
function renderThreadComments(comment, pendingComment = null) {
|
||||
const nestedComments = comment?.replies?.pages?.topAll?.comments || {};
|
||||
const commentKeys = Object.keys(nestedComments);
|
||||
|
||||
const renderedComments = commentKeys.map(key => {
|
||||
const comment = comments[key];
|
||||
const { replies: { pages: { topAll: { comments: nestedComments = [] } = {} } = {} } = {} } = comment;
|
||||
if (comment.replyCount > 0 && nestedComments) {
|
||||
const renderedNestedComments = renderThreadComments(nestedComments);
|
||||
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();
|
||||
|
||||
if (pendingComment?.parentCid === comment?.cid) {
|
||||
renderedComments.push(pendingComment);
|
||||
}
|
||||
|
||||
const sortedComments = renderedComments.sort((a, b) => a.timestamp - b.timestamp);
|
||||
return sortedComments;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user