elseware-ui 2.31.12 → 2.31.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +37 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -17986,14 +17986,27 @@ function CommentThread({
|
|
|
17986
17986
|
loadComments();
|
|
17987
17987
|
}, [dataSource, resolvedConfig.commentsPerPage]);
|
|
17988
17988
|
function updateReplyCacheComment(cache, commentId, updater) {
|
|
17989
|
-
|
|
17989
|
+
const next = {};
|
|
17990
|
+
for (const [parentId, replies] of Object.entries(cache)) {
|
|
17991
|
+
next[parentId] = replies.map(
|
|
17992
|
+
(reply) => reply.id === commentId ? updater(reply) : reply
|
|
17993
|
+
);
|
|
17994
|
+
}
|
|
17995
|
+
return next;
|
|
17996
|
+
}
|
|
17997
|
+
function removeCommentTreeFromCache(cache, commentId) {
|
|
17998
|
+
const childIds = cache[commentId]?.map((reply) => reply.id) ?? [];
|
|
17999
|
+
let next = Object.fromEntries(
|
|
17990
18000
|
Object.entries(cache).map(([parentId, replies]) => [
|
|
17991
18001
|
parentId,
|
|
17992
|
-
replies.
|
|
17993
|
-
(reply) => reply.id === commentId ? updater(reply) : reply
|
|
17994
|
-
)
|
|
18002
|
+
replies.filter((reply) => reply.id !== commentId)
|
|
17995
18003
|
])
|
|
17996
18004
|
);
|
|
18005
|
+
delete next[commentId];
|
|
18006
|
+
for (const childId of childIds) {
|
|
18007
|
+
next = removeCommentTreeFromCache(next, childId);
|
|
18008
|
+
}
|
|
18009
|
+
return next;
|
|
17997
18010
|
}
|
|
17998
18011
|
async function handleCreateComment(content) {
|
|
17999
18012
|
const comment = await dataSource.createComment({
|
|
@@ -18002,6 +18015,25 @@ function CommentThread({
|
|
|
18002
18015
|
});
|
|
18003
18016
|
setComments((prev) => [comment, ...prev]);
|
|
18004
18017
|
}
|
|
18018
|
+
async function handleDeleteComment(comment) {
|
|
18019
|
+
await dataSource.deleteComment(comment.id);
|
|
18020
|
+
setComments((prev) => prev.filter((item) => item.id !== comment.id));
|
|
18021
|
+
setReplyCache((prev) => removeCommentTreeFromCache(prev, comment.id));
|
|
18022
|
+
if (comment.parentCommentId) {
|
|
18023
|
+
setComments(
|
|
18024
|
+
(prev) => updateComment(prev, comment.parentCommentId, (item) => ({
|
|
18025
|
+
...item,
|
|
18026
|
+
replyCount: Math.max(item.replyCount - 1, 0)
|
|
18027
|
+
}))
|
|
18028
|
+
);
|
|
18029
|
+
setReplyCache(
|
|
18030
|
+
(prev) => updateReplyCacheComment(prev, comment.parentCommentId, (item) => ({
|
|
18031
|
+
...item,
|
|
18032
|
+
replyCount: Math.max(item.replyCount - 1, 0)
|
|
18033
|
+
}))
|
|
18034
|
+
);
|
|
18035
|
+
}
|
|
18036
|
+
}
|
|
18005
18037
|
async function handleReply(parentComment, content) {
|
|
18006
18038
|
const reply = await dataSource.createComment({
|
|
18007
18039
|
content,
|
|
@@ -18112,7 +18144,7 @@ function CommentThread({
|
|
|
18112
18144
|
onReply: handleReply,
|
|
18113
18145
|
onLoadReplies: handleLoadReplies,
|
|
18114
18146
|
onEdit,
|
|
18115
|
-
onDelete,
|
|
18147
|
+
onDelete: handleDeleteComment,
|
|
18116
18148
|
onReport
|
|
18117
18149
|
}
|
|
18118
18150
|
)
|