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.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
- setComments(
18005
- (prev) => prev.map(
18006
- (comment) => comment.id === parentComment.id ? {
18007
- ...comment,
18008
- replyCount: comment.replyCount + 1
18009
- } : comment
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
- setComments(
18033
- (prev) => updateComment(prev, comment.id, (item) => ({
18034
- ...item,
18035
- likes: optimistic.likes,
18036
- dislikes: optimistic.dislikes,
18037
- liked: optimistic.liked,
18038
- disliked: optimistic.disliked
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
- setComments(
18055
- (prev) => updateComment(prev, comment.id, (item) => ({
18056
- ...item,
18057
- likes: optimistic.likes,
18058
- dislikes: optimistic.dislikes,
18059
- liked: optimistic.liked,
18060
- disliked: optimistic.disliked
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) {