@edifice.io/react 2.1.2-develop-pedago.20250319191946 → 2.1.2-develop-pedago.20250320195838

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.
@@ -29,7 +29,7 @@ const DeleteModal = /* @__PURE__ */ lazy(() => import("./DeleteModal.js")), Comm
29
29
  } = comment, [ref, onFocus, resizeTextarea] = useAutosizeTextarea(!0), [isDeleteModalOpen, setIsDeleteModalOpen] = useState(!1), {
30
30
  t
31
31
  } = useTranslation(), {
32
- comments,
32
+ defaultComments,
33
33
  editCommentId,
34
34
  options,
35
35
  type,
@@ -39,7 +39,7 @@ const DeleteModal = /* @__PURE__ */ lazy(() => import("./DeleteModal.js")), Comm
39
39
  handleReset,
40
40
  handleUpdateComment,
41
41
  handleReplyToComment
42
- } = useCommentsContext(), replies = (comments == null ? void 0 : comments.filter((comm) => comm.replyTo === comment.id)) ?? [], hasReplies = replies.length > 0, hasAllDeletedReplies = replies.every((reply) => reply.deleted), isEditing = editCommentId === comment.id, handleChangeContent = (event) => {
42
+ } = useCommentsContext(), replies = (defaultComments == null ? void 0 : defaultComments.filter((comm) => comm.replyTo === comment.id)) ?? [], hasReplies = replies.length > 0, hasAllDeletedReplies = replies.every((reply) => reply.deleted), isEditing = editCommentId === comment.id, handleChangeContent = (event) => {
43
43
  resizeTextarea(), setValue(event.target.value);
44
44
  };
45
45
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -6,15 +6,15 @@ function CommentList() {
6
6
  const {
7
7
  user
8
8
  } = useEdificeClient(), {
9
- comments,
9
+ displayedComments,
10
10
  profiles
11
11
  } = useCommentsContext();
12
- return comments == null ? void 0 : comments.map((comment) => {
12
+ return displayedComments == null ? void 0 : displayedComments.map((comment) => {
13
13
  var _a;
14
14
  const {
15
15
  authorId
16
16
  } = comment, profile = ((_a = profiles == null ? void 0 : profiles.find((user2) => (user2 == null ? void 0 : user2.userId) === authorId)) == null ? void 0 : _a.profile) ?? "Guest";
17
- return /* @__PURE__ */ jsx("div", { children: !comment.replyTo && /* @__PURE__ */ jsx(Comment, { comment, profile, userId: user == null ? void 0 : user.userId }) }, comment.id);
17
+ return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Comment, { comment, profile, userId: user == null ? void 0 : user.userId }) }, comment.id);
18
18
  });
19
19
  }
20
20
  export {
@@ -8,7 +8,6 @@ const CommentReplies = ({
8
8
  parentComment
9
9
  }) => {
10
10
  const {
11
- comments,
12
11
  profiles,
13
12
  options,
14
13
  replyToCommentId
@@ -21,7 +20,6 @@ const CommentReplies = ({
21
20
  handleMoreReplies
22
21
  } = useCommentReplies({
23
22
  parentComment,
24
- comments,
25
23
  profiles,
26
24
  options
27
25
  }), showCommentForm = replyToCommentId === parentComment.id && !parentComment.deleted;
@@ -1,7 +1,8 @@
1
1
  import { RightRole } from '@edifice.io/client';
2
2
  import { CommentOptions, CommentProps, CommentType, UserProfileResult } from '../types';
3
3
  export declare const CommentContext: import('react').Context<{
4
- comments: CommentProps[] | undefined;
4
+ displayedComments: CommentProps[] | undefined;
5
+ defaultComments: CommentProps[] | undefined;
5
6
  editCommentId: string | null;
6
7
  replyToCommentId: string | null;
7
8
  profiles: (UserProfileResult | undefined)[];
@@ -1,7 +1,6 @@
1
1
  import { CommentOptions, CommentProps, UserProfileResult } from '../types';
2
- export declare const useCommentReplies: ({ parentComment, comments, profiles, options, }: {
2
+ export declare const useCommentReplies: ({ parentComment, profiles, options, }: {
3
3
  parentComment: CommentProps;
4
- comments: CommentProps[] | undefined;
5
4
  profiles: (UserProfileResult | undefined)[];
6
5
  options: Partial<CommentOptions>;
7
6
  }) => {
@@ -10,6 +9,5 @@ export declare const useCommentReplies: ({ parentComment, comments, profiles, op
10
9
  profile: "Student" | "Teacher" | "Relative" | "Personnel" | "Guest";
11
10
  slicedReplies: CommentProps[];
12
11
  defaultReplies: CommentProps[];
13
- orphanReplies: CommentProps[];
14
12
  handleMoreReplies: () => void;
15
13
  };
@@ -1,9 +1,9 @@
1
1
  import { useState } from "react";
2
2
  import { useTranslation } from "react-i18next";
3
3
  import { useEdificeClient } from "../../../providers/EdificeClientProvider/EdificeClientProvider.hook.js";
4
+ import { useCommentsContext } from "./useCommentsContext.js";
4
5
  const useCommentReplies = ({
5
6
  parentComment,
6
- comments,
7
7
  profiles,
8
8
  options
9
9
  }) => {
@@ -12,19 +12,20 @@ const useCommentReplies = ({
12
12
  maxReplies,
13
13
  additionalReplies
14
14
  } = options, [repliesLimit, setRepliesLimit] = useState(maxReplies), {
15
+ defaultComments
16
+ } = useCommentsContext(), {
15
17
  user
16
18
  } = useEdificeClient(), {
17
19
  t
18
20
  } = useTranslation(), {
19
21
  authorId
20
- } = parentComment, profile = ((_a = profiles == null ? void 0 : profiles.find((user2) => (user2 == null ? void 0 : user2.userId) === authorId)) == null ? void 0 : _a.profile) ?? "Guest", defaultReplies = (comments == null ? void 0 : comments.filter((comment) => comment.replyTo === parentComment.id)) ?? [], slicedReplies = (defaultReplies == null ? void 0 : defaultReplies.sort((a, b) => b.createdAt - a.createdAt).slice(0, repliesLimit)) ?? [], orphanReplies = (comments == null ? void 0 : comments.filter((comment) => comment.replyTo && !comments.find((c) => c.id === comment.replyTo))) ?? [];
22
+ } = parentComment, profile = ((_a = profiles == null ? void 0 : profiles.find((user2) => (user2 == null ? void 0 : user2.userId) === authorId)) == null ? void 0 : _a.profile) ?? "Guest", defaultReplies = (defaultComments == null ? void 0 : defaultComments.filter((comment) => comment.replyTo === parentComment.id)) ?? [], slicedReplies = (defaultReplies == null ? void 0 : defaultReplies.sort((a, b) => b.createdAt - a.createdAt).slice(0, repliesLimit)) ?? [];
21
23
  return {
22
24
  t,
23
25
  user,
24
26
  profile,
25
27
  slicedReplies,
26
28
  defaultReplies,
27
- orphanReplies,
28
29
  handleMoreReplies: () => {
29
30
  const newLimit = slicedReplies.length + (additionalReplies ?? 2);
30
31
  newLimit !== slicedReplies.length && setRepliesLimit(newLimit);
@@ -5,6 +5,7 @@ export declare const useComments: ({ defaultComments, options, type, callbacks,
5
5
  type: CommentType;
6
6
  callbacks: CommentCallbacks | null;
7
7
  }) => {
8
+ t: import('i18next').TFunction<"translation", undefined>;
8
9
  profilesQueries: {
9
10
  data: ({
10
11
  userId: string;
@@ -15,14 +16,12 @@ export declare const useComments: ({ defaultComments, options, type, callbacks,
15
16
  title: string;
16
17
  user: import('@edifice.io/client').IUserInfo | undefined;
17
18
  emptyscreenPath: string;
18
- defaultCommentsCount: number;
19
- comments: CommentProps[];
19
+ displayedComments: CommentProps[];
20
+ showMoreComments: boolean;
20
21
  editCommentId: string | null;
21
22
  setEditCommentId: import('react').Dispatch<import('react').SetStateAction<string | null>>;
22
23
  replyToCommentId: string | null;
23
24
  setReplyToCommentId: import('react').Dispatch<import('react').SetStateAction<string | null>>;
24
- commentsCount: number;
25
- t: import('i18next').TFunction<"translation", undefined>;
26
25
  handleMoreComments: () => void;
27
26
  handleDeleteComment: (id: string) => void;
28
27
  handleCreateComment: (content: string, replyTo?: string) => void;
@@ -14,31 +14,34 @@ const useComments = ({
14
14
  t
15
15
  } = useTranslation(), {
16
16
  user
17
- } = useEdificeClient(), usersIds = Array.from(new Set(defaultComments == null ? void 0 : defaultComments.map((comment) => comment.authorId))), profilesQueries = useProfileQueries(usersIds), comments = useMemo(
18
- () => type === "edit" ? (defaultComments == null ? void 0 : defaultComments.sort((a, b) => b.createdAt - a.createdAt).slice(0, commentLimit)) ?? [] : (defaultComments == null ? void 0 : defaultComments.sort((a, b) => b.createdAt - a.createdAt)) ?? [],
17
+ } = useEdificeClient(), usersIds = Array.from(new Set(defaultComments == null ? void 0 : defaultComments.map((comment) => comment.authorId))), profilesQueries = useProfileQueries(usersIds), idsOfDeletedCommentWithNoReply = useMemo(() => (defaultComments == null ? void 0 : defaultComments.filter((comment) => comment.deleted && !defaultComments.some((c) => c.replyTo === comment.id)).map((comment) => comment.id)) ?? [], [defaultComments]), displayedComments = useMemo(
18
+ () => {
19
+ var _a2;
20
+ const result = ((_a2 = defaultComments == null ? void 0 : defaultComments.filter((comment) => !comment.replyTo && !idsOfDeletedCommentWithNoReply.includes(comment.id))) == null ? void 0 : _a2.sort((a, b) => b.createdAt - a.createdAt)) ?? [];
21
+ return type === "edit" ? result.slice(0, commentLimit) ?? [] : result;
22
+ },
19
23
  // eslint-disable-next-line react-hooks/exhaustive-deps
20
24
  [commentLimit, defaultComments]
21
- ), commentsCount = ((_a = comments == null ? void 0 : comments.filter((comment) => !comment.deleted)) == null ? void 0 : _a.length) ?? 0, defaultCommentsCount = ((_b = defaultComments == null ? void 0 : defaultComments.filter((comment) => !comment.deleted)) == null ? void 0 : _b.length) ?? 0, title = defaultCommentsCount && defaultCommentsCount > 1 ? t("comment.several", {
22
- number: defaultCommentsCount
25
+ ), showMoreComments = (displayedComments == null ? void 0 : displayedComments.length) < (((_a = defaultComments == null ? void 0 : defaultComments.filter((comment) => !comment.replyTo && !idsOfDeletedCommentWithNoReply.includes(comment.id))) == null ? void 0 : _a.length) ?? 0), titleCommentsCount = ((_b = defaultComments == null ? void 0 : defaultComments.filter((comment) => !comment.deleted)) == null ? void 0 : _b.length) ?? 0, title = titleCommentsCount > 1 ? t("comment.several", {
26
+ number: titleCommentsCount
23
27
  }) : t("comment.little", {
24
- number: defaultCommentsCount
28
+ number: titleCommentsCount
25
29
  });
26
30
  return {
31
+ t,
27
32
  profilesQueries,
28
33
  title,
29
34
  user,
30
35
  emptyscreenPath: illuPad,
31
- defaultCommentsCount,
32
- comments,
36
+ displayedComments,
37
+ showMoreComments,
33
38
  editCommentId,
34
39
  setEditCommentId,
35
40
  replyToCommentId,
36
41
  setReplyToCommentId,
37
- commentsCount,
38
- t,
39
42
  handleMoreComments: () => {
40
- const newLimit = (comments == null ? void 0 : comments.length) + (options.additionalComments ?? 5);
41
- newLimit !== comments.length && setCommentLimit(newLimit);
43
+ const newLimit = displayedComments.length + (options.additionalComments ?? 5);
44
+ newLimit !== displayedComments.length && setCommentLimit(newLimit);
42
45
  },
43
46
  handleDeleteComment: (id) => {
44
47
  type === "edit" && (callbacks == null || callbacks.delete(id));
@@ -1,5 +1,6 @@
1
1
  export declare const useCommentsContext: () => {
2
- comments: import('../types').CommentProps[] | undefined;
2
+ displayedComments: import('../types').CommentProps[] | undefined;
3
+ defaultComments: import('../types').CommentProps[] | undefined;
3
4
  editCommentId: string | null;
4
5
  replyToCommentId: string | null;
5
6
  profiles: (import('../types').UserProfileResult | undefined)[];
@@ -28,13 +28,12 @@ const CommentProvider = ({
28
28
  title,
29
29
  user,
30
30
  emptyscreenPath,
31
- defaultCommentsCount,
32
- comments,
31
+ displayedComments,
32
+ showMoreComments,
33
33
  editCommentId,
34
34
  setEditCommentId,
35
35
  replyToCommentId,
36
36
  setReplyToCommentId,
37
- commentsCount,
38
37
  t,
39
38
  handleMoreComments,
40
39
  handleDeleteComment,
@@ -50,7 +49,8 @@ const CommentProvider = ({
50
49
  options
51
50
  }), userRights = type === "edit" ? props.rights : void 0, values = useMemo(
52
51
  () => ({
53
- comments,
52
+ displayedComments,
53
+ defaultComments,
54
54
  profiles: profilesQueries.data,
55
55
  editCommentId,
56
56
  replyToCommentId,
@@ -67,7 +67,7 @@ const CommentProvider = ({
67
67
  handleReset
68
68
  }),
69
69
  // eslint-disable-next-line react-hooks/exhaustive-deps
70
- [comments, editCommentId, profilesQueries, options]
70
+ [displayedComments, editCommentId, profilesQueries, options]
71
71
  );
72
72
  return /* @__PURE__ */ jsx(CommentContext.Provider, { value: values, children: /* @__PURE__ */ jsxs("div", { className: "my-24", children: [
73
73
  /* @__PURE__ */ jsx(CommentHeader, { title }),
@@ -75,10 +75,10 @@ const CommentProvider = ({
75
75
  user && /* @__PURE__ */ jsx(CommentForm, { userId: user.userId }),
76
76
  profilesQueries.isLoading ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
77
77
  /* @__PURE__ */ jsx(CommentList, {}),
78
- commentsCount !== defaultCommentsCount && /* @__PURE__ */ jsx(Button, { variant: "ghost", color: "tertiary", onClick: handleMoreComments, className: "my-16", children: t("comment.more") })
78
+ showMoreComments && /* @__PURE__ */ jsx(Button, { variant: "ghost", color: "tertiary", onClick: handleMoreComments, className: "my-16", children: t("comment.more") })
79
79
  ] })
80
80
  ] }),
81
- !commentsCount && type === "edit" && /* @__PURE__ */ jsxs("div", { className: "comments-emptyscreen", children: [
81
+ !displayedComments.length && type === "edit" && /* @__PURE__ */ jsxs("div", { className: "comments-emptyscreen", children: [
82
82
  /* @__PURE__ */ jsx("div", { className: "comments-emptyscreen-wrapper", children: /* @__PURE__ */ jsx(EmptyScreen, { imageSrc: emptyscreenPath, size: 150 }) }),
83
83
  /* @__PURE__ */ jsx("p", { children: t("comment.emptyscreen") })
84
84
  ] })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edifice.io/react",
3
- "version": "2.1.2-develop-pedago.20250319191946",
3
+ "version": "2.1.2-develop-pedago.20250320195838",
4
4
  "description": "Edifice React Library",
5
5
  "keywords": [
6
6
  "react",
@@ -118,9 +118,9 @@
118
118
  "react-slugify": "^3.0.3",
119
119
  "swiper": "^10.1.0",
120
120
  "ua-parser-js": "^1.0.36",
121
- "@edifice.io/bootstrap": "2.1.2-develop-pedago.20250319191946",
122
- "@edifice.io/tiptap-extensions": "2.1.2-develop-pedago.20250319191946",
123
- "@edifice.io/utilities": "2.1.2-develop-pedago.20250319191946"
121
+ "@edifice.io/bootstrap": "2.1.2-develop-pedago.20250320195838",
122
+ "@edifice.io/tiptap-extensions": "2.1.2-develop-pedago.20250320195838",
123
+ "@edifice.io/utilities": "2.1.2-develop-pedago.20250320195838"
124
124
  },
125
125
  "devDependencies": {
126
126
  "@babel/plugin-transform-react-pure-annotations": "^7.23.3",
@@ -151,8 +151,8 @@
151
151
  "vite": "^5.4.11",
152
152
  "vite-plugin-dts": "^4.1.0",
153
153
  "vite-tsconfig-paths": "^5.0.1",
154
- "@edifice.io/config": "2.1.2-develop-pedago.20250319191946",
155
- "@edifice.io/client": "2.1.2-develop-pedago.20250319191946"
154
+ "@edifice.io/client": "2.1.2-develop-pedago.20250320195838",
155
+ "@edifice.io/config": "2.1.2-develop-pedago.20250320195838"
156
156
  },
157
157
  "peerDependencies": {
158
158
  "@react-spring/web": "^9.7.5",