fix pending reply logic, add it to board

This commit is contained in:
Tom
2023-04-25 14:34:48 +02:00
parent 467a979c78
commit aa875b9c9a
4 changed files with 154 additions and 97 deletions
-30
View File
@@ -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;
-24
View File
@@ -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;