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.js
CHANGED
|
@@ -18014,14 +18014,27 @@ function CommentThread({
|
|
|
18014
18014
|
loadComments();
|
|
18015
18015
|
}, [dataSource, resolvedConfig.commentsPerPage]);
|
|
18016
18016
|
function updateReplyCacheComment(cache, commentId, updater) {
|
|
18017
|
-
|
|
18017
|
+
const next = {};
|
|
18018
|
+
for (const [parentId, replies] of Object.entries(cache)) {
|
|
18019
|
+
next[parentId] = replies.map(
|
|
18020
|
+
(reply) => reply.id === commentId ? updater(reply) : reply
|
|
18021
|
+
);
|
|
18022
|
+
}
|
|
18023
|
+
return next;
|
|
18024
|
+
}
|
|
18025
|
+
function removeCommentTreeFromCache(cache, commentId) {
|
|
18026
|
+
const childIds = cache[commentId]?.map((reply) => reply.id) ?? [];
|
|
18027
|
+
let next = Object.fromEntries(
|
|
18018
18028
|
Object.entries(cache).map(([parentId, replies]) => [
|
|
18019
18029
|
parentId,
|
|
18020
|
-
replies.
|
|
18021
|
-
(reply) => reply.id === commentId ? updater(reply) : reply
|
|
18022
|
-
)
|
|
18030
|
+
replies.filter((reply) => reply.id !== commentId)
|
|
18023
18031
|
])
|
|
18024
18032
|
);
|
|
18033
|
+
delete next[commentId];
|
|
18034
|
+
for (const childId of childIds) {
|
|
18035
|
+
next = removeCommentTreeFromCache(next, childId);
|
|
18036
|
+
}
|
|
18037
|
+
return next;
|
|
18025
18038
|
}
|
|
18026
18039
|
async function handleCreateComment(content) {
|
|
18027
18040
|
const comment = await dataSource.createComment({
|
|
@@ -18030,6 +18043,25 @@ function CommentThread({
|
|
|
18030
18043
|
});
|
|
18031
18044
|
setComments((prev) => [comment, ...prev]);
|
|
18032
18045
|
}
|
|
18046
|
+
async function handleDeleteComment(comment) {
|
|
18047
|
+
await dataSource.deleteComment(comment.id);
|
|
18048
|
+
setComments((prev) => prev.filter((item) => item.id !== comment.id));
|
|
18049
|
+
setReplyCache((prev) => removeCommentTreeFromCache(prev, comment.id));
|
|
18050
|
+
if (comment.parentCommentId) {
|
|
18051
|
+
setComments(
|
|
18052
|
+
(prev) => updateComment(prev, comment.parentCommentId, (item) => ({
|
|
18053
|
+
...item,
|
|
18054
|
+
replyCount: Math.max(item.replyCount - 1, 0)
|
|
18055
|
+
}))
|
|
18056
|
+
);
|
|
18057
|
+
setReplyCache(
|
|
18058
|
+
(prev) => updateReplyCacheComment(prev, comment.parentCommentId, (item) => ({
|
|
18059
|
+
...item,
|
|
18060
|
+
replyCount: Math.max(item.replyCount - 1, 0)
|
|
18061
|
+
}))
|
|
18062
|
+
);
|
|
18063
|
+
}
|
|
18064
|
+
}
|
|
18033
18065
|
async function handleReply(parentComment, content) {
|
|
18034
18066
|
const reply = await dataSource.createComment({
|
|
18035
18067
|
content,
|
|
@@ -18140,7 +18172,7 @@ function CommentThread({
|
|
|
18140
18172
|
onReply: handleReply,
|
|
18141
18173
|
onLoadReplies: handleLoadReplies,
|
|
18142
18174
|
onEdit,
|
|
18143
|
-
onDelete,
|
|
18175
|
+
onDelete: handleDeleteComment,
|
|
18144
18176
|
onReport
|
|
18145
18177
|
}
|
|
18146
18178
|
)
|