mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
17 lines
629 B
JavaScript
17 lines
629 B
JavaScript
function renderThreadComments(comments) {
|
|||
|
|
const commentKeys = Object.keys(comments);
|
||
|
|
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);
|
||
|
|
return [comment, ...renderedNestedComments];
|
||
|
|
}
|
||
|
|
return [comment];
|
||
|
|
}).flat();
|
||
|
|
|
||
|
|
const sortedComments = renderedComments.sort((a, b) => a.timestamp - b.timestamp);
|
||
|
|
return sortedComments;
|
||
|
|
}
|
||
|
|
|
||
|
|
export default renderThreadComments;
|