elseware-ui 2.31.14 → 2.31.16

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.mjs CHANGED
@@ -17957,6 +17957,7 @@ function CommentThread({
17957
17957
  loading = false,
17958
17958
  components,
17959
17959
  config,
17960
+ updatedComment,
17960
17961
  onEdit,
17961
17962
  onDelete,
17962
17963
  onReport
@@ -17966,6 +17967,7 @@ function CommentThread({
17966
17967
  const [replyCache, setReplyCache] = useState(
17967
17968
  {}
17968
17969
  );
17970
+ const replyCacheRef = useRef(replyCache);
17969
17971
  const ComposerComponent = components?.Composer ?? CommentComposer_default;
17970
17972
  const resolvedConfig = {
17971
17973
  ...DEFAULT_COMMENT_THREAD_CONFIG,
@@ -17985,6 +17987,45 @@ function CommentThread({
17985
17987
  }
17986
17988
  loadComments();
17987
17989
  }, [dataSource, resolvedConfig.commentsPerPage]);
17990
+ useEffect(() => {
17991
+ replyCacheRef.current = replyCache;
17992
+ }, [replyCache]);
17993
+ useEffect(() => {
17994
+ let cancelled = false;
17995
+ async function refreshLoadedReplies() {
17996
+ const parentIds = Object.keys(replyCacheRef.current);
17997
+ if (!parentIds.length) {
17998
+ return;
17999
+ }
18000
+ try {
18001
+ const entries = await Promise.all(
18002
+ parentIds.map(async (parentId) => {
18003
+ const result = await dataSource.getReplies(parentId, {
18004
+ limit: resolvedConfig.repliesPerPage
18005
+ });
18006
+ return [parentId, result.items];
18007
+ })
18008
+ );
18009
+ if (cancelled) {
18010
+ return;
18011
+ }
18012
+ setReplyCache((prev) => {
18013
+ const next = { ...prev };
18014
+ for (const [parentId, replies] of entries) {
18015
+ if (parentId in next) {
18016
+ next[parentId] = replies;
18017
+ }
18018
+ }
18019
+ return next;
18020
+ });
18021
+ } catch {
18022
+ }
18023
+ }
18024
+ void refreshLoadedReplies();
18025
+ return () => {
18026
+ cancelled = true;
18027
+ };
18028
+ }, [dataSource, resolvedConfig.repliesPerPage]);
17988
18029
  function updateReplyCacheComment(cache, commentId, updater) {
17989
18030
  const next = {};
17990
18031
  for (const [parentId, replies] of Object.entries(cache)) {
@@ -18038,6 +18079,12 @@ function CommentThread({
18038
18079
  setComments((prev) => updateComment(prev, commentId, updater));
18039
18080
  setReplyCache((prev) => updateReplyCacheComment(prev, commentId, updater));
18040
18081
  }
18082
+ useEffect(() => {
18083
+ if (!updatedComment) {
18084
+ return;
18085
+ }
18086
+ updateCommentEverywhere(updatedComment.id, () => updatedComment);
18087
+ }, [updatedComment]);
18041
18088
  async function handleReply(parentComment, content) {
18042
18089
  const reply = await dataSource.createComment({
18043
18090
  content,
@@ -18123,9 +18170,11 @@ function CommentThread({
18123
18170
  );
18124
18171
  }
18125
18172
  }
18126
- function handleEditComment(updatedComment) {
18127
- updateCommentEverywhere(updatedComment.id, () => updatedComment);
18128
- onEdit?.(updatedComment);
18173
+ async function handleEditComment(comment) {
18174
+ const updatedComment2 = await onEdit?.(comment);
18175
+ if (updatedComment2) {
18176
+ updateCommentEverywhere(updatedComment2.id, () => updatedComment2);
18177
+ }
18129
18178
  }
18130
18179
  if (loading || isLoadingComments) {
18131
18180
  return /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-6", children: "Loading comments..." });