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 CHANGED
@@ -18013,6 +18013,16 @@ function CommentThread({
18013
18013
  }
18014
18014
  loadComments();
18015
18015
  }, [dataSource, resolvedConfig.commentsPerPage]);
18016
+ function updateReplyCacheComment(cache, commentId, updater) {
18017
+ return Object.fromEntries(
18018
+ Object.entries(cache).map(([parentId, replies]) => [
18019
+ parentId,
18020
+ replies.map(
18021
+ (reply) => reply.id === commentId ? updater(reply) : reply
18022
+ )
18023
+ ])
18024
+ );
18025
+ }
18016
18026
  async function handleCreateComment(content) {
18017
18027
  const comment = await dataSource.createComment({
18018
18028
  content,
@@ -18029,13 +18039,18 @@ function CommentThread({
18029
18039
  ...prev,
18030
18040
  [parentComment.id]: [...prev[parentComment.id] ?? [], reply]
18031
18041
  }));
18032
- setComments(
18033
- (prev) => prev.map(
18034
- (comment) => comment.id === parentComment.id ? {
18035
- ...comment,
18036
- replyCount: comment.replyCount + 1
18037
- } : comment
18038
- )
18042
+ const incrementReplyCount = (items) => items.map(
18043
+ (item) => item.id === parentComment.id ? {
18044
+ ...item,
18045
+ replyCount: item.replyCount + 1
18046
+ } : item
18047
+ );
18048
+ setComments((prev) => incrementReplyCount(prev));
18049
+ setReplyCache(
18050
+ (prev) => updateReplyCacheComment(prev, parentComment.id, (item) => ({
18051
+ ...item,
18052
+ replyCount: item.replyCount + 1
18053
+ }))
18039
18054
  );
18040
18055
  }
18041
18056
  async function handleLoadReplies(comment) {
@@ -18057,19 +18072,22 @@ function CommentThread({
18057
18072
  likes: comment.liked ? Math.max(comment.likes - 1, 0) : comment.likes + 1,
18058
18073
  dislikes: comment.disliked ? Math.max(comment.dislikes - 1, 0) : comment.dislikes
18059
18074
  };
18060
- setComments(
18061
- (prev) => updateComment(prev, comment.id, (item) => ({
18062
- ...item,
18063
- likes: optimistic.likes,
18064
- dislikes: optimistic.dislikes,
18065
- liked: optimistic.liked,
18066
- disliked: optimistic.disliked
18067
- }))
18068
- );
18075
+ const updater = (item) => ({
18076
+ ...item,
18077
+ likes: optimistic.likes,
18078
+ dislikes: optimistic.dislikes,
18079
+ liked: optimistic.liked,
18080
+ disliked: optimistic.disliked
18081
+ });
18082
+ setComments((prev) => updateComment(prev, comment.id, updater));
18083
+ setReplyCache((prev) => updateReplyCacheComment(prev, comment.id, updater));
18069
18084
  try {
18070
18085
  await dataSource.toggleLike(comment.id);
18071
18086
  } catch {
18072
18087
  setComments((prev) => updateComment(prev, comment.id, () => comment));
18088
+ setReplyCache(
18089
+ (prev) => updateReplyCacheComment(prev, comment.id, () => comment)
18090
+ );
18073
18091
  }
18074
18092
  }
18075
18093
  async function handleDislike(comment) {
@@ -18079,19 +18097,22 @@ function CommentThread({
18079
18097
  likes: comment.liked ? Math.max(comment.likes - 1, 0) : comment.likes,
18080
18098
  dislikes: comment.disliked ? Math.max(comment.dislikes - 1, 0) : comment.dislikes + 1
18081
18099
  };
18082
- setComments(
18083
- (prev) => updateComment(prev, comment.id, (item) => ({
18084
- ...item,
18085
- likes: optimistic.likes,
18086
- dislikes: optimistic.dislikes,
18087
- liked: optimistic.liked,
18088
- disliked: optimistic.disliked
18089
- }))
18090
- );
18100
+ const updater = (item) => ({
18101
+ ...item,
18102
+ likes: optimistic.likes,
18103
+ dislikes: optimistic.dislikes,
18104
+ liked: optimistic.liked,
18105
+ disliked: optimistic.disliked
18106
+ });
18107
+ setComments((prev) => updateComment(prev, comment.id, updater));
18108
+ setReplyCache((prev) => updateReplyCacheComment(prev, comment.id, updater));
18091
18109
  try {
18092
18110
  await dataSource.toggleDislike(comment.id);
18093
18111
  } catch {
18094
18112
  setComments((prev) => updateComment(prev, comment.id, () => comment));
18113
+ setReplyCache(
18114
+ (prev) => updateReplyCacheComment(prev, comment.id, () => comment)
18115
+ );
18095
18116
  }
18096
18117
  }
18097
18118
  if (loading || isLoadingComments) {