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

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
+ limitedSortedParentComments,
10
10
  profiles
11
11
  } = useCommentsContext();
12
- return comments == null ? void 0 : comments.map((comment) => {
12
+ return limitedSortedParentComments == null ? void 0 : limitedSortedParentComments.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
+ limitedSortedParentComments: 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);
@@ -15,13 +15,13 @@ export declare const useComments: ({ defaultComments, options, type, callbacks,
15
15
  title: string;
16
16
  user: import('@edifice.io/client').IUserInfo | undefined;
17
17
  emptyscreenPath: string;
18
- defaultCommentsCount: number;
19
- comments: CommentProps[];
18
+ defaultParentCommentsCount: number;
19
+ limitedSortedParentComments: CommentProps[];
20
20
  editCommentId: string | null;
21
21
  setEditCommentId: import('react').Dispatch<import('react').SetStateAction<string | null>>;
22
22
  replyToCommentId: string | null;
23
23
  setReplyToCommentId: import('react').Dispatch<import('react').SetStateAction<string | null>>;
24
- commentsCount: number;
24
+ limitedSortedParentCommentsCount: number;
25
25
  t: import('i18next').TFunction<"translation", undefined>;
26
26
  handleMoreComments: () => void;
27
27
  handleDeleteComment: (id: string) => void;
@@ -9,36 +9,40 @@ const useComments = ({
9
9
  type,
10
10
  callbacks
11
11
  }) => {
12
- var _a, _b;
12
+ var _a;
13
13
  const [editCommentId, setEditCommentId] = useState(null), [replyToCommentId, setReplyToCommentId] = useState(null), [commentLimit, setCommentLimit] = useState(options.maxComments), {
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), limitedSortedParentComments = useMemo(
18
+ () => {
19
+ var _a2;
20
+ const filteredAndSortedComments = ((_a2 = defaultComments == null ? void 0 : defaultComments.filter((comment) => !comment.replyTo)) == null ? void 0 : _a2.sort((a, b) => b.createdAt - a.createdAt)) ?? [];
21
+ return type === "edit" ? filteredAndSortedComments.slice(0, commentLimit) ?? [] : filteredAndSortedComments;
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
+ ), limitedSortedParentCommentsCount = (limitedSortedParentComments == null ? void 0 : limitedSortedParentComments.length) ?? 0, defaultParentCommentsCount = ((_a = defaultComments == null ? void 0 : defaultComments.filter((comment) => !comment.replyTo)) == null ? void 0 : _a.length) ?? 0, title = defaultComments != null && defaultComments.length && (defaultComments == null ? void 0 : defaultComments.length) > 1 ? t("comment.several", {
26
+ number: defaultComments == null ? void 0 : defaultComments.length
23
27
  }) : t("comment.little", {
24
- number: defaultCommentsCount
28
+ number: defaultComments == null ? void 0 : defaultComments.length
25
29
  });
26
30
  return {
27
31
  profilesQueries,
28
32
  title,
29
33
  user,
30
34
  emptyscreenPath: illuPad,
31
- defaultCommentsCount,
32
- comments,
35
+ defaultParentCommentsCount,
36
+ limitedSortedParentComments,
33
37
  editCommentId,
34
38
  setEditCommentId,
35
39
  replyToCommentId,
36
40
  setReplyToCommentId,
37
- commentsCount,
41
+ limitedSortedParentCommentsCount,
38
42
  t,
39
43
  handleMoreComments: () => {
40
- const newLimit = (comments == null ? void 0 : comments.length) + (options.additionalComments ?? 5);
41
- newLimit !== comments.length && setCommentLimit(newLimit);
44
+ const filteredComments = limitedSortedParentComments == null ? void 0 : limitedSortedParentComments.filter((comment) => !comment.replyTo), newLimit = (filteredComments == null ? void 0 : filteredComments.length) + (options.additionalComments ?? 5);
45
+ newLimit !== (filteredComments == null ? void 0 : filteredComments.length) && setCommentLimit(newLimit);
42
46
  },
43
47
  handleDeleteComment: (id) => {
44
48
  type === "edit" && (callbacks == null || callbacks.delete(id));
@@ -1,5 +1,6 @@
1
1
  export declare const useCommentsContext: () => {
2
- comments: import('../types').CommentProps[] | undefined;
2
+ limitedSortedParentComments: 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,13 @@ const CommentProvider = ({
28
28
  title,
29
29
  user,
30
30
  emptyscreenPath,
31
- defaultCommentsCount,
32
- comments,
31
+ defaultParentCommentsCount,
32
+ limitedSortedParentComments,
33
33
  editCommentId,
34
34
  setEditCommentId,
35
35
  replyToCommentId,
36
36
  setReplyToCommentId,
37
- commentsCount,
37
+ limitedSortedParentCommentsCount,
38
38
  t,
39
39
  handleMoreComments,
40
40
  handleDeleteComment,
@@ -50,7 +50,8 @@ const CommentProvider = ({
50
50
  options
51
51
  }), userRights = type === "edit" ? props.rights : void 0, values = useMemo(
52
52
  () => ({
53
- comments,
53
+ limitedSortedParentComments,
54
+ defaultComments,
54
55
  profiles: profilesQueries.data,
55
56
  editCommentId,
56
57
  replyToCommentId,
@@ -67,7 +68,7 @@ const CommentProvider = ({
67
68
  handleReset
68
69
  }),
69
70
  // eslint-disable-next-line react-hooks/exhaustive-deps
70
- [comments, editCommentId, profilesQueries, options]
71
+ [limitedSortedParentComments, editCommentId, profilesQueries, options]
71
72
  );
72
73
  return /* @__PURE__ */ jsx(CommentContext.Provider, { value: values, children: /* @__PURE__ */ jsxs("div", { className: "my-24", children: [
73
74
  /* @__PURE__ */ jsx(CommentHeader, { title }),
@@ -75,10 +76,10 @@ const CommentProvider = ({
75
76
  user && /* @__PURE__ */ jsx(CommentForm, { userId: user.userId }),
76
77
  profilesQueries.isLoading ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
77
78
  /* @__PURE__ */ jsx(CommentList, {}),
78
- commentsCount !== defaultCommentsCount && /* @__PURE__ */ jsx(Button, { variant: "ghost", color: "tertiary", onClick: handleMoreComments, className: "my-16", children: t("comment.more") })
79
+ limitedSortedParentCommentsCount !== defaultParentCommentsCount && /* @__PURE__ */ jsx(Button, { variant: "ghost", color: "tertiary", onClick: handleMoreComments, className: "my-16", children: t("comment.more") })
79
80
  ] })
80
81
  ] }),
81
- !commentsCount && type === "edit" && /* @__PURE__ */ jsxs("div", { className: "comments-emptyscreen", children: [
82
+ !limitedSortedParentCommentsCount && type === "edit" && /* @__PURE__ */ jsxs("div", { className: "comments-emptyscreen", children: [
82
83
  /* @__PURE__ */ jsx("div", { className: "comments-emptyscreen-wrapper", children: /* @__PURE__ */ jsx(EmptyScreen, { imageSrc: emptyscreenPath, size: 150 }) }),
83
84
  /* @__PURE__ */ jsx("p", { children: t("comment.emptyscreen") })
84
85
  ] })
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.20250320142932",
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.20250320142932",
122
+ "@edifice.io/tiptap-extensions": "2.1.2-develop-pedago.20250320142932",
123
+ "@edifice.io/utilities": "2.1.2-develop-pedago.20250320142932"
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/config": "2.1.2-develop-pedago.20250320142932",
155
+ "@edifice.io/client": "2.1.2-develop-pedago.20250320142932"
156
156
  },
157
157
  "peerDependencies": {
158
158
  "@react-spring/web": "^9.7.5",