elseware-ui 2.31.13 → 2.31.15
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.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +51 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -17966,6 +17966,7 @@ function CommentThread({
|
|
|
17966
17966
|
const [replyCache, setReplyCache] = useState(
|
|
17967
17967
|
{}
|
|
17968
17968
|
);
|
|
17969
|
+
const replyCacheRef = useRef(replyCache);
|
|
17969
17970
|
const ComposerComponent = components?.Composer ?? CommentComposer_default;
|
|
17970
17971
|
const resolvedConfig = {
|
|
17971
17972
|
...DEFAULT_COMMENT_THREAD_CONFIG,
|
|
@@ -17985,6 +17986,45 @@ function CommentThread({
|
|
|
17985
17986
|
}
|
|
17986
17987
|
loadComments();
|
|
17987
17988
|
}, [dataSource, resolvedConfig.commentsPerPage]);
|
|
17989
|
+
useEffect(() => {
|
|
17990
|
+
replyCacheRef.current = replyCache;
|
|
17991
|
+
}, [replyCache]);
|
|
17992
|
+
useEffect(() => {
|
|
17993
|
+
let cancelled = false;
|
|
17994
|
+
async function refreshLoadedReplies() {
|
|
17995
|
+
const parentIds = Object.keys(replyCacheRef.current);
|
|
17996
|
+
if (!parentIds.length) {
|
|
17997
|
+
return;
|
|
17998
|
+
}
|
|
17999
|
+
try {
|
|
18000
|
+
const entries = await Promise.all(
|
|
18001
|
+
parentIds.map(async (parentId) => {
|
|
18002
|
+
const result = await dataSource.getReplies(parentId, {
|
|
18003
|
+
limit: resolvedConfig.repliesPerPage
|
|
18004
|
+
});
|
|
18005
|
+
return [parentId, result.items];
|
|
18006
|
+
})
|
|
18007
|
+
);
|
|
18008
|
+
if (cancelled) {
|
|
18009
|
+
return;
|
|
18010
|
+
}
|
|
18011
|
+
setReplyCache((prev) => {
|
|
18012
|
+
const next = { ...prev };
|
|
18013
|
+
for (const [parentId, replies] of entries) {
|
|
18014
|
+
if (parentId in next) {
|
|
18015
|
+
next[parentId] = replies;
|
|
18016
|
+
}
|
|
18017
|
+
}
|
|
18018
|
+
return next;
|
|
18019
|
+
});
|
|
18020
|
+
} catch {
|
|
18021
|
+
}
|
|
18022
|
+
}
|
|
18023
|
+
void refreshLoadedReplies();
|
|
18024
|
+
return () => {
|
|
18025
|
+
cancelled = true;
|
|
18026
|
+
};
|
|
18027
|
+
}, [dataSource, resolvedConfig.repliesPerPage]);
|
|
17988
18028
|
function updateReplyCacheComment(cache, commentId, updater) {
|
|
17989
18029
|
const next = {};
|
|
17990
18030
|
for (const [parentId, replies] of Object.entries(cache)) {
|
|
@@ -18034,6 +18074,10 @@ function CommentThread({
|
|
|
18034
18074
|
);
|
|
18035
18075
|
}
|
|
18036
18076
|
}
|
|
18077
|
+
function updateCommentEverywhere(commentId, updater) {
|
|
18078
|
+
setComments((prev) => updateComment(prev, commentId, updater));
|
|
18079
|
+
setReplyCache((prev) => updateReplyCacheComment(prev, commentId, updater));
|
|
18080
|
+
}
|
|
18037
18081
|
async function handleReply(parentComment, content) {
|
|
18038
18082
|
const reply = await dataSource.createComment({
|
|
18039
18083
|
content,
|
|
@@ -18119,6 +18163,12 @@ function CommentThread({
|
|
|
18119
18163
|
);
|
|
18120
18164
|
}
|
|
18121
18165
|
}
|
|
18166
|
+
async function handleEditComment(comment) {
|
|
18167
|
+
const updatedComment = await onEdit?.(comment);
|
|
18168
|
+
if (updatedComment) {
|
|
18169
|
+
updateCommentEverywhere(updatedComment.id, () => updatedComment);
|
|
18170
|
+
}
|
|
18171
|
+
}
|
|
18122
18172
|
if (loading || isLoadingComments) {
|
|
18123
18173
|
return /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-6", children: "Loading comments..." });
|
|
18124
18174
|
}
|
|
@@ -18143,7 +18193,7 @@ function CommentThread({
|
|
|
18143
18193
|
onDislike: handleDislike,
|
|
18144
18194
|
onReply: handleReply,
|
|
18145
18195
|
onLoadReplies: handleLoadReplies,
|
|
18146
|
-
onEdit,
|
|
18196
|
+
onEdit: handleEditComment,
|
|
18147
18197
|
onDelete: handleDeleteComment,
|
|
18148
18198
|
onReport
|
|
18149
18199
|
}
|