2023-03-08 09:49:42 +01:00
|
|
|
function renderThreadComments(comments) {
|
2023-04-15 21:11:37 +02:00
|
|
|
const commentKeys = Object.keys(comments? comments : {});
|
2023-03-08 09:49:42 +01:00
|
|
|
const renderedComments = commentKeys.map(key => {
|
|
|
|
|
const comment = comments[key];
|
2023-04-15 18:12:46 +02:00
|
|
|
const { replies: { pages: { topAll: { comments: nestedComments = [] } = {} } = {} } = {} } = comment;
|
2023-03-08 09:49:42 +01:00
|
|
|
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;
|