elseware-ui 2.31.11 → 2.31.12
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 +46 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -17985,6 +17985,16 @@ function CommentThread({
|
|
|
17985
17985
|
}
|
|
17986
17986
|
loadComments();
|
|
17987
17987
|
}, [dataSource, resolvedConfig.commentsPerPage]);
|
|
17988
|
+
function updateReplyCacheComment(cache, commentId, updater) {
|
|
17989
|
+
return Object.fromEntries(
|
|
17990
|
+
Object.entries(cache).map(([parentId, replies]) => [
|
|
17991
|
+
parentId,
|
|
17992
|
+
replies.map(
|
|
17993
|
+
(reply) => reply.id === commentId ? updater(reply) : reply
|
|
17994
|
+
)
|
|
17995
|
+
])
|
|
17996
|
+
);
|
|
17997
|
+
}
|
|
17988
17998
|
async function handleCreateComment(content) {
|
|
17989
17999
|
const comment = await dataSource.createComment({
|
|
17990
18000
|
content,
|
|
@@ -18001,13 +18011,18 @@ function CommentThread({
|
|
|
18001
18011
|
...prev,
|
|
18002
18012
|
[parentComment.id]: [...prev[parentComment.id] ?? [], reply]
|
|
18003
18013
|
}));
|
|
18004
|
-
|
|
18005
|
-
(
|
|
18006
|
-
|
|
18007
|
-
|
|
18008
|
-
|
|
18009
|
-
|
|
18010
|
-
|
|
18014
|
+
const incrementReplyCount = (items) => items.map(
|
|
18015
|
+
(item) => item.id === parentComment.id ? {
|
|
18016
|
+
...item,
|
|
18017
|
+
replyCount: item.replyCount + 1
|
|
18018
|
+
} : item
|
|
18019
|
+
);
|
|
18020
|
+
setComments((prev) => incrementReplyCount(prev));
|
|
18021
|
+
setReplyCache(
|
|
18022
|
+
(prev) => updateReplyCacheComment(prev, parentComment.id, (item) => ({
|
|
18023
|
+
...item,
|
|
18024
|
+
replyCount: item.replyCount + 1
|
|
18025
|
+
}))
|
|
18011
18026
|
);
|
|
18012
18027
|
}
|
|
18013
18028
|
async function handleLoadReplies(comment) {
|
|
@@ -18029,19 +18044,22 @@ function CommentThread({
|
|
|
18029
18044
|
likes: comment.liked ? Math.max(comment.likes - 1, 0) : comment.likes + 1,
|
|
18030
18045
|
dislikes: comment.disliked ? Math.max(comment.dislikes - 1, 0) : comment.dislikes
|
|
18031
18046
|
};
|
|
18032
|
-
|
|
18033
|
-
|
|
18034
|
-
|
|
18035
|
-
|
|
18036
|
-
|
|
18037
|
-
|
|
18038
|
-
|
|
18039
|
-
|
|
18040
|
-
);
|
|
18047
|
+
const updater = (item) => ({
|
|
18048
|
+
...item,
|
|
18049
|
+
likes: optimistic.likes,
|
|
18050
|
+
dislikes: optimistic.dislikes,
|
|
18051
|
+
liked: optimistic.liked,
|
|
18052
|
+
disliked: optimistic.disliked
|
|
18053
|
+
});
|
|
18054
|
+
setComments((prev) => updateComment(prev, comment.id, updater));
|
|
18055
|
+
setReplyCache((prev) => updateReplyCacheComment(prev, comment.id, updater));
|
|
18041
18056
|
try {
|
|
18042
18057
|
await dataSource.toggleLike(comment.id);
|
|
18043
18058
|
} catch {
|
|
18044
18059
|
setComments((prev) => updateComment(prev, comment.id, () => comment));
|
|
18060
|
+
setReplyCache(
|
|
18061
|
+
(prev) => updateReplyCacheComment(prev, comment.id, () => comment)
|
|
18062
|
+
);
|
|
18045
18063
|
}
|
|
18046
18064
|
}
|
|
18047
18065
|
async function handleDislike(comment) {
|
|
@@ -18051,19 +18069,22 @@ function CommentThread({
|
|
|
18051
18069
|
likes: comment.liked ? Math.max(comment.likes - 1, 0) : comment.likes,
|
|
18052
18070
|
dislikes: comment.disliked ? Math.max(comment.dislikes - 1, 0) : comment.dislikes + 1
|
|
18053
18071
|
};
|
|
18054
|
-
|
|
18055
|
-
|
|
18056
|
-
|
|
18057
|
-
|
|
18058
|
-
|
|
18059
|
-
|
|
18060
|
-
|
|
18061
|
-
|
|
18062
|
-
);
|
|
18072
|
+
const updater = (item) => ({
|
|
18073
|
+
...item,
|
|
18074
|
+
likes: optimistic.likes,
|
|
18075
|
+
dislikes: optimistic.dislikes,
|
|
18076
|
+
liked: optimistic.liked,
|
|
18077
|
+
disliked: optimistic.disliked
|
|
18078
|
+
});
|
|
18079
|
+
setComments((prev) => updateComment(prev, comment.id, updater));
|
|
18080
|
+
setReplyCache((prev) => updateReplyCacheComment(prev, comment.id, updater));
|
|
18063
18081
|
try {
|
|
18064
18082
|
await dataSource.toggleDislike(comment.id);
|
|
18065
18083
|
} catch {
|
|
18066
18084
|
setComments((prev) => updateComment(prev, comment.id, () => comment));
|
|
18085
|
+
setReplyCache(
|
|
18086
|
+
(prev) => updateReplyCacheComment(prev, comment.id, () => comment)
|
|
18087
|
+
);
|
|
18067
18088
|
}
|
|
18068
18089
|
}
|
|
18069
18090
|
if (loading || isLoadingComments) {
|