@burdenoff/microfe-buildmyiq 2026.1102.1 → 2026.1102.2
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/buildmyiq/components/BuiDiscussion.d.ts +8 -4
- package/dist/buildmyiq/components/BuiDiscussion.d.ts.map +1 -1
- package/dist/buildmyiq/components/BuiDiscussion.js +190 -87
- package/dist/buildmyiq/components/BuiDiscussion.js.map +1 -1
- package/dist/buildmyiq/hooks/useBuiComments.d.ts +50 -10
- package/dist/buildmyiq/hooks/useBuiComments.d.ts.map +1 -1
- package/dist/buildmyiq/hooks/useBuiComments.js +67 -23
- package/dist/buildmyiq/hooks/useBuiComments.js.map +1 -1
- package/dist/buildmyiq/hooks/useBuildmyiqApi.d.ts +52 -0
- package/dist/buildmyiq/hooks/useBuildmyiqApi.d.ts.map +1 -1
- package/dist/buildmyiq/hooks/useBuildmyiqApi.js +169 -122
- package/dist/buildmyiq/hooks/useBuildmyiqApi.js.map +1 -1
- package/dist/buildmyiq/pages/catalog/CatalogPage.d.ts.map +1 -1
- package/dist/buildmyiq/pages/catalog/CatalogPage.js +97 -68
- package/dist/buildmyiq/pages/catalog/CatalogPage.js.map +1 -1
- package/dist/buildmyiq/pages/catalog/CourseDetailPage.d.ts.map +1 -1
- package/dist/buildmyiq/pages/catalog/CourseDetailPage.js +270 -208
- package/dist/buildmyiq/pages/catalog/CourseDetailPage.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* BuiDiscussion — a comment
|
|
2
|
+
* BuiDiscussion — a threaded comment discussion on any Buildmyiq entity (Integration B).
|
|
3
3
|
* @module buildmyiq/components/BuiDiscussion
|
|
4
4
|
*
|
|
5
5
|
* Reuses the platform EntityComment API (`getEntityComments` /
|
|
6
|
-
* `createEntityComment`
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* `createEntityComment` / `add|removeEntityCommentReaction`) keyed by
|
|
7
|
+
* `(entityType, entityId)` — no buildmyiq-svc change. Renders the discussion
|
|
8
|
+
* as threads: every comment can be replied to (replies nest beneath their
|
|
9
|
+
* parent, indentation capped so deep threads stay readable) and liked.
|
|
10
|
+
* Posting and reacting are enforced by the workspace gateway's `@rbac`
|
|
11
|
+
* directives on the conversations subgraph; a refused write shows its error
|
|
12
|
+
* inline. Robust to empty state and errors.
|
|
9
13
|
*/
|
|
10
14
|
interface BuiDiscussionProps {
|
|
11
15
|
entityType: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuiDiscussion.d.ts","sourceRoot":"","sources":["../../../src/buildmyiq/components/BuiDiscussion.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"BuiDiscussion.d.ts","sourceRoot":"","sources":["../../../src/buildmyiq/components/BuiDiscussion.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAqBH,UAAU,kBAAkB;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAuGD,wBAAgB,aAAa,CAAC,EAC5B,UAAU,EACV,QAAQ,EACR,KAAoB,EACpB,WAAkE,GACnE,EAAE,kBAAkB,+BA0LpB"}
|
|
@@ -1,111 +1,214 @@
|
|
|
1
1
|
import { useBuildmyiq as e } from "../context/BuildmyiqContext.js";
|
|
2
2
|
import "../context/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { useTr as t } from "../shared/hooks/useTr.js";
|
|
4
|
+
import { cn as n } from "../utils/cn.js";
|
|
5
|
+
import { formatDateTime as r } from "../utils/formatters.js";
|
|
6
|
+
import { EmptyState as i } from "./EmptyState.js";
|
|
7
|
+
import { ErrorView as a, LoadingView as o, Section as s } from "./StateViews.js";
|
|
8
|
+
import { countComments as c, likeState as l, useBuiComments as u, useBuiToggleCommentLike as d, useEcoCreateComment as f } from "../hooks/useBuiComments.js";
|
|
7
9
|
import "../hooks/index.js";
|
|
8
|
-
import { useState as
|
|
9
|
-
import { MessageSquare as
|
|
10
|
-
import { jsx as
|
|
11
|
-
import { Button as
|
|
10
|
+
import { useState as p } from "react";
|
|
11
|
+
import { MessageSquare as m, Reply as h, Send as g, ThumbsUp as _ } from "lucide-react";
|
|
12
|
+
import { Fragment as v, jsx as y, jsxs as b } from "react/jsx-runtime";
|
|
13
|
+
import { Button as x, Textarea as S } from "@burdenoff/fe-libs/ui";
|
|
12
14
|
//#region src/buildmyiq/components/BuiDiscussion.tsx
|
|
13
|
-
|
|
15
|
+
var C = 3;
|
|
16
|
+
function w(e) {
|
|
14
17
|
if (!e) return "You";
|
|
15
18
|
let t = [e.firstName, e.lastName].filter(Boolean).join(" ").trim();
|
|
16
19
|
return e.name || t || e.username || e.email || "You";
|
|
17
20
|
}
|
|
18
|
-
function
|
|
21
|
+
function T(e) {
|
|
19
22
|
let t = e.trim();
|
|
20
23
|
return t ? t[0].toUpperCase() : "?";
|
|
21
24
|
}
|
|
22
|
-
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
var E = (e, t) => e instanceof Error ? e.message : t, D = ({ initial: e, placeholder: t, ariaLabel: n, submitLabel: r, pendingLabel: i, errorFallback: a, autoFocus: o, onSubmit: s, onCancel: c, cancelLabel: l }) => {
|
|
26
|
+
let [u, d] = p(""), [f, m] = p(null), [h, _] = p(!1);
|
|
27
|
+
return /* @__PURE__ */ b("div", {
|
|
28
|
+
className: "flex gap-3",
|
|
29
|
+
children: [/* @__PURE__ */ y("div", {
|
|
30
|
+
className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-action-primary-bg/15 text-sm font-semibold text-action-primary-bg",
|
|
31
|
+
children: e
|
|
32
|
+
}), /* @__PURE__ */ b("div", {
|
|
33
|
+
className: "min-w-0 flex-1",
|
|
34
|
+
children: [/* @__PURE__ */ y(S, {
|
|
35
|
+
value: u,
|
|
36
|
+
onChange: (e) => d(e.target.value),
|
|
37
|
+
placeholder: t,
|
|
38
|
+
"aria-label": n,
|
|
39
|
+
rows: 2,
|
|
40
|
+
autoFocus: o
|
|
41
|
+
}), /* @__PURE__ */ b("div", {
|
|
42
|
+
className: "mt-2 flex items-center justify-end gap-2",
|
|
43
|
+
children: [
|
|
44
|
+
f && /* @__PURE__ */ y("span", {
|
|
45
|
+
role: "alert",
|
|
46
|
+
className: "me-auto text-xs text-status-error-text",
|
|
47
|
+
children: f
|
|
48
|
+
}),
|
|
49
|
+
c && /* @__PURE__ */ y(x, {
|
|
50
|
+
size: "sm",
|
|
51
|
+
variant: "ghost",
|
|
52
|
+
onClick: c,
|
|
53
|
+
disabled: h,
|
|
54
|
+
children: l
|
|
55
|
+
}),
|
|
56
|
+
/* @__PURE__ */ b(x, {
|
|
57
|
+
size: "sm",
|
|
58
|
+
onClick: async () => {
|
|
59
|
+
let e = u.trim();
|
|
60
|
+
if (!(!e || h)) {
|
|
61
|
+
m(null), _(!0);
|
|
62
|
+
try {
|
|
63
|
+
await s(e), d("");
|
|
64
|
+
} catch (e) {
|
|
65
|
+
m(E(e, a));
|
|
66
|
+
} finally {
|
|
67
|
+
_(!1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
disabled: !u.trim() || h,
|
|
72
|
+
children: [/* @__PURE__ */ y(g, { className: "me-1.5 h-4 w-4" }), h ? i : r]
|
|
73
|
+
})
|
|
74
|
+
]
|
|
75
|
+
})]
|
|
76
|
+
})]
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
function O({ entityType: g, entityId: S, title: O = "Discussion", description: k = "Coordinate review and verification with your team." }) {
|
|
80
|
+
let { currentUser: A } = e(), j = t(), { data: M, isLoading: N, isError: P, refetch: F } = u(g, S), I = f(g, S), L = d(g, S), [R, z] = p(null), [B, V] = p(null), H = w(A), U = A?.id, W = (e) => U && e.authorId === U ? H : j("buildmyiq.discussion.workspaceMember", "Workspace member"), G = M?.threads ?? [], K = c(G), q = async (e, t) => {
|
|
81
|
+
V(null);
|
|
82
|
+
try {
|
|
83
|
+
await L.mutateAsync({
|
|
84
|
+
commentId: e.id,
|
|
85
|
+
like: !t
|
|
86
|
+
});
|
|
87
|
+
} catch (e) {
|
|
88
|
+
V(E(e, j("buildmyiq.discussion.likeError", "Could not update the like.")));
|
|
32
89
|
}
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
children: [/* @__PURE__ */ f("div", {
|
|
90
|
+
}, J = (e, t) => {
|
|
91
|
+
let i = W(e), a = e.content.text ?? e.content.markdown ?? "", { count: o, likedByMe: s } = l(e, U), c = L.isPending && L.variables?.commentId === e.id, u = t < C;
|
|
92
|
+
return /* @__PURE__ */ b("li", {
|
|
93
|
+
className: "flex flex-col gap-3",
|
|
94
|
+
"data-testid": "bui-discussion-comment",
|
|
95
|
+
children: [/* @__PURE__ */ b("div", {
|
|
40
96
|
className: "flex gap-3",
|
|
41
|
-
children: [/* @__PURE__ */
|
|
42
|
-
className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-
|
|
43
|
-
children:
|
|
44
|
-
}), /* @__PURE__ */
|
|
45
|
-
className: "flex-1",
|
|
46
|
-
children: [
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
97
|
+
children: [/* @__PURE__ */ y("div", {
|
|
98
|
+
className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-bg-sunken text-sm font-semibold text-text-secondary",
|
|
99
|
+
children: T(i)
|
|
100
|
+
}), /* @__PURE__ */ b("div", {
|
|
101
|
+
className: "min-w-0 flex-1",
|
|
102
|
+
children: [
|
|
103
|
+
/* @__PURE__ */ b("div", {
|
|
104
|
+
className: "flex flex-wrap items-baseline gap-x-2",
|
|
105
|
+
children: [/* @__PURE__ */ y("span", {
|
|
106
|
+
className: "text-sm font-semibold text-text-primary",
|
|
107
|
+
children: i
|
|
108
|
+
}), /* @__PURE__ */ b("span", {
|
|
109
|
+
className: "text-xs text-text-tertiary",
|
|
110
|
+
children: [r(e.createdAt), e.edited ? ` · ${j("buildmyiq.discussion.edited", "edited")}` : ""]
|
|
111
|
+
})]
|
|
112
|
+
}),
|
|
113
|
+
/* @__PURE__ */ y("p", {
|
|
114
|
+
className: "mt-0.5 whitespace-pre-wrap break-words text-sm text-text-secondary",
|
|
115
|
+
children: a
|
|
116
|
+
}),
|
|
117
|
+
/* @__PURE__ */ b("div", {
|
|
118
|
+
className: "mt-1.5 flex items-center gap-1",
|
|
119
|
+
children: [/* @__PURE__ */ b(x, {
|
|
120
|
+
size: "sm",
|
|
121
|
+
variant: "ghost",
|
|
122
|
+
className: n("h-7 px-2 text-xs", s && "text-action-primary-bg"),
|
|
123
|
+
"aria-pressed": s,
|
|
124
|
+
"aria-label": s ? j("buildmyiq.discussion.unlikeAria", "Unlike comment") : j("buildmyiq.discussion.likeAria", "Like comment"),
|
|
125
|
+
disabled: !U || c,
|
|
126
|
+
onClick: () => q(e, s),
|
|
127
|
+
children: [/* @__PURE__ */ y(_, { className: n("me-1 h-3.5 w-3.5", s && "fill-current") }), o > 0 ? /* @__PURE__ */ y("span", {
|
|
128
|
+
className: "tabular-nums",
|
|
129
|
+
children: o
|
|
130
|
+
}) : j("buildmyiq.discussion.like", "Like")]
|
|
131
|
+
}), /* @__PURE__ */ b(x, {
|
|
132
|
+
size: "sm",
|
|
133
|
+
variant: "ghost",
|
|
134
|
+
className: "h-7 px-2 text-xs",
|
|
135
|
+
"aria-expanded": R === e.id,
|
|
136
|
+
onClick: () => z(R === e.id ? null : e.id),
|
|
137
|
+
children: [/* @__PURE__ */ y(h, { className: "me-1 h-3.5 w-3.5 rtl:-scale-x-100" }), j("buildmyiq.discussion.reply", "Reply")]
|
|
138
|
+
})]
|
|
139
|
+
})
|
|
140
|
+
]
|
|
65
141
|
})]
|
|
66
|
-
}), /* @__PURE__ */
|
|
142
|
+
}), (R === e.id || e.replies.length > 0) && /* @__PURE__ */ b("div", {
|
|
143
|
+
className: n("flex flex-col gap-3", u && "ms-4 border-s border-border-seam ps-4 sm:ms-11"),
|
|
144
|
+
children: [R === e.id && /* @__PURE__ */ y(D, {
|
|
145
|
+
initial: T(H),
|
|
146
|
+
placeholder: j("buildmyiq.discussion.replyPlaceholder", "Write a reply…"),
|
|
147
|
+
ariaLabel: j("buildmyiq.discussion.replyAria", "Reply"),
|
|
148
|
+
submitLabel: j("buildmyiq.discussion.replyButton", "Reply"),
|
|
149
|
+
pendingLabel: j("buildmyiq.discussion.posting", "Posting…"),
|
|
150
|
+
cancelLabel: j("buildmyiq.discussion.cancel", "Cancel"),
|
|
151
|
+
errorFallback: j("buildmyiq.discussion.postError", "Failed to post comment."),
|
|
152
|
+
autoFocus: !0,
|
|
153
|
+
onCancel: () => z(null),
|
|
154
|
+
onSubmit: async (t) => {
|
|
155
|
+
await I.mutateAsync({
|
|
156
|
+
text: t,
|
|
157
|
+
parentCommentId: e.id
|
|
158
|
+
}), z((t) => t === e.id ? null : t);
|
|
159
|
+
}
|
|
160
|
+
}), e.replies.length > 0 && /* @__PURE__ */ y("ul", {
|
|
161
|
+
className: "flex flex-col gap-4",
|
|
162
|
+
children: e.replies.map((e) => J(e, t + 1))
|
|
163
|
+
})]
|
|
164
|
+
})]
|
|
165
|
+
}, e.id);
|
|
166
|
+
};
|
|
167
|
+
return /* @__PURE__ */ y(s, {
|
|
168
|
+
title: O,
|
|
169
|
+
description: k,
|
|
170
|
+
children: /* @__PURE__ */ b("div", {
|
|
171
|
+
className: "rounded-xl border border-border-seam bg-bg-surface/40 p-4",
|
|
172
|
+
children: [/* @__PURE__ */ y(D, {
|
|
173
|
+
initial: T(H),
|
|
174
|
+
placeholder: j("buildmyiq.discussion.placeholder", "Add a comment for your team…"),
|
|
175
|
+
ariaLabel: j("buildmyiq.discussion.commentAria", "Comment"),
|
|
176
|
+
submitLabel: j("buildmyiq.discussion.commentButton", "Comment"),
|
|
177
|
+
pendingLabel: j("buildmyiq.discussion.posting", "Posting…"),
|
|
178
|
+
errorFallback: j("buildmyiq.discussion.postError", "Failed to post comment."),
|
|
179
|
+
onSubmit: async (e) => {
|
|
180
|
+
await I.mutateAsync({ text: e });
|
|
181
|
+
}
|
|
182
|
+
}), /* @__PURE__ */ y("div", {
|
|
67
183
|
className: "mt-4 border-t border-border-seam pt-4",
|
|
68
|
-
children:
|
|
69
|
-
message: "Couldn't load the discussion.",
|
|
70
|
-
onRetry: () =>
|
|
71
|
-
}) :
|
|
184
|
+
children: N ? /* @__PURE__ */ y(o, { label: j("buildmyiq.discussion.loading", "Loading discussion…") }) : P ? /* @__PURE__ */ y(a, {
|
|
185
|
+
message: j("buildmyiq.discussion.loadError", "Couldn't load the discussion."),
|
|
186
|
+
onRetry: () => F()
|
|
187
|
+
}) : G.length === 0 ? /* @__PURE__ */ y(i, {
|
|
72
188
|
illustration: "empty-data",
|
|
73
|
-
icon: /* @__PURE__ */
|
|
74
|
-
title: "No comments yet",
|
|
75
|
-
description: "Start the discussion by adding the first comment."
|
|
76
|
-
}) : /* @__PURE__ */
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
children: [/* @__PURE__ */ d("span", {
|
|
90
|
-
className: "text-sm font-semibold text-text-primary",
|
|
91
|
-
children: n
|
|
92
|
-
}), /* @__PURE__ */ f("span", {
|
|
93
|
-
className: "text-xs text-text-tertiary",
|
|
94
|
-
children: [t(e.createdAt), e.edited ? " · edited" : ""]
|
|
95
|
-
})]
|
|
96
|
-
}), /* @__PURE__ */ d("p", {
|
|
97
|
-
className: "mt-0.5 whitespace-pre-wrap break-words text-sm text-text-secondary",
|
|
98
|
-
children: r
|
|
99
|
-
})]
|
|
100
|
-
})]
|
|
101
|
-
}, e.id);
|
|
189
|
+
icon: /* @__PURE__ */ y(m, { className: "h-9 w-9" }),
|
|
190
|
+
title: j("buildmyiq.discussion.emptyTitle", "No comments yet"),
|
|
191
|
+
description: j("buildmyiq.discussion.emptyDescription", "Start the discussion by adding the first comment.")
|
|
192
|
+
}) : /* @__PURE__ */ b(v, { children: [
|
|
193
|
+
/* @__PURE__ */ y("p", {
|
|
194
|
+
className: "mb-3 text-xs text-text-tertiary",
|
|
195
|
+
children: j(K === 1 ? "buildmyiq.discussion.countSingular" : "buildmyiq.discussion.countPlural", K === 1 ? "{{n}} comment" : "{{n}} comments", { n: K })
|
|
196
|
+
}),
|
|
197
|
+
B && /* @__PURE__ */ y("p", {
|
|
198
|
+
role: "alert",
|
|
199
|
+
className: "mb-3 text-xs text-status-error-text",
|
|
200
|
+
children: B
|
|
201
|
+
}),
|
|
202
|
+
/* @__PURE__ */ y("ul", {
|
|
203
|
+
className: "flex flex-col gap-4",
|
|
204
|
+
children: G.map((e) => J(e, 0))
|
|
102
205
|
})
|
|
103
|
-
})
|
|
206
|
+
] })
|
|
104
207
|
})]
|
|
105
208
|
})
|
|
106
209
|
});
|
|
107
210
|
}
|
|
108
211
|
//#endregion
|
|
109
|
-
export {
|
|
212
|
+
export { O as BuiDiscussion };
|
|
110
213
|
|
|
111
214
|
//# sourceMappingURL=BuiDiscussion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuiDiscussion.js","names":[],"sources":["../../../src/buildmyiq/components/BuiDiscussion.tsx"],"sourcesContent":["/**\n * BuiDiscussion — a comment thread on any Buildmyiq entity (Integration B).\n * @module buildmyiq/components/BuiDiscussion\n *\n * Reuses the platform EntityComment API (`getEntityComments` /\n * `createEntityComment`) keyed by `(entityType, entityId)` — no buildmyiq-svc change.\n * Renders root comments (author, body, time) + a composer. Robust to empty\n * state and errors.\n */\n\nimport { useState } from 'react';\nimport { MessageSquare, Send } from 'lucide-react';\nimport { Button, Textarea } from '@burdenoff/fe-libs/ui';\nimport { Section, LoadingView, ErrorView } from './StateViews';\nimport { EmptyState } from './EmptyState';\nimport { useBuildmyiq } from '../context';\nimport { useBuiComments, useEcoCreateComment, type BuiComment } from '../hooks';\nimport { formatDateTime } from '../utils/formatters';\n\ninterface BuiDiscussionProps {\n entityType: string;\n entityId: string;\n title?: string;\n description?: string;\n}\n\nfunction displayName(user: ReturnType<typeof useBuildmyiq>['currentUser']): string {\n if (!user) return 'You';\n const full = [user.firstName, user.lastName].filter(Boolean).join(' ').trim();\n return user.name || full || user.username || user.email || 'You';\n}\n\nfunction initialFor(label: string): string {\n const trimmed = label.trim();\n return trimmed ? trimmed[0]!.toUpperCase() : '?';\n}\n\nexport function BuiDiscussion({\n entityType,\n entityId,\n title = 'Discussion',\n description = 'Coordinate review and verification with your team.',\n}: BuiDiscussionProps) {\n const { currentUser } = useBuildmyiq();\n const { data, isLoading, isError, refetch } = useBuiComments(entityType, entityId);\n const createComment = useEcoCreateComment(entityType, entityId);\n\n const [draft, setDraft] = useState('');\n const [error, setError] = useState<string | null>(null);\n\n const selfName = displayName(currentUser);\n\n const authorLabel = (comment: BuiComment): string =>\n currentUser?.id && comment.authorId === currentUser.id ? selfName : 'Workspace member';\n\n const handleSubmit = async () => {\n const text = draft.trim();\n if (!text) return;\n setError(null);\n try {\n await createComment.mutateAsync(text);\n setDraft('');\n } catch (err) {\n setError(err instanceof Error ? err.message : 'Failed to post comment.');\n }\n };\n\n const comments = data?.items ?? [];\n\n return (\n <Section title={title} description={description}>\n <div className=\"rounded-xl border border-border-seam bg-bg-surface/40 p-4\">\n {/* Composer */}\n <div className=\"flex gap-3\">\n <div className=\"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-action-primary-bg/15 text-sm font-semibold text-action-primary-bg\">\n {initialFor(selfName)}\n </div>\n <div className=\"flex-1\">\n <Textarea\n value={draft}\n onChange={(e) => setDraft(e.target.value)}\n placeholder=\"Add a comment for your team…\"\n aria-label=\"Comment\"\n rows={2}\n />\n <div className=\"mt-2 flex items-center justify-end gap-2\">\n {error && (\n <span role=\"alert\" className=\"me-auto text-xs text-status-error-text\">\n {error}\n </span>\n )}\n <Button\n size=\"sm\"\n onClick={handleSubmit}\n disabled={!draft.trim() || createComment.isPending}\n >\n <Send className=\"me-1.5 h-4 w-4\" />\n {createComment.isPending ? 'Posting…' : 'Comment'}\n </Button>\n </div>\n </div>\n </div>\n\n {/* Thread */}\n <div className=\"mt-4 border-t border-border-seam pt-4\">\n {isLoading ? (\n <LoadingView label=\"Loading discussion…\" />\n ) : isError ? (\n <ErrorView message=\"Couldn't load the discussion.\" onRetry={() => refetch()} />\n ) : comments.length === 0 ? (\n <EmptyState\n illustration=\"empty-data\"\n icon={<MessageSquare className=\"h-9 w-9\" />}\n title=\"No comments yet\"\n description=\"Start the discussion by adding the first comment.\"\n />\n ) : (\n <ul className=\"flex flex-col gap-4\">\n {comments.map((comment) => {\n const label = authorLabel(comment);\n const body = comment.content.text ?? comment.content.markdown ?? '';\n return (\n <li key={comment.id} className=\"flex gap-3\">\n <div className=\"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-bg-sunken text-sm font-semibold text-text-secondary\">\n {initialFor(label)}\n </div>\n <div className=\"min-w-0 flex-1\">\n <div className=\"flex flex-wrap items-baseline gap-x-2\">\n <span className=\"text-sm font-semibold text-text-primary\">{label}</span>\n <span className=\"text-xs text-text-tertiary\">\n {formatDateTime(comment.createdAt)}\n {comment.edited ? ' · edited' : ''}\n </span>\n </div>\n <p className=\"mt-0.5 whitespace-pre-wrap break-words text-s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,EAgBb;KAER,CAAC;IACC,CAAA;GAEH,CAAA,CACF;;CACE,CAAA;AAEb"}
|
|
1
|
+
{"version":3,"file":"BuiDiscussion.js","names":[],"sources":["../../../src/buildmyiq/components/BuiDiscussion.tsx"],"sourcesContent":["/**\n * BuiDiscussion — a threaded comment discussion on any Buildmyiq entity (Integration B).\n * @module buildmyiq/components/BuiDiscussion\n *\n * Reuses the platform EntityComment API (`getEntityComments` /\n * `createEntityComment` / `add|removeEntityCommentReaction`) keyed by\n * `(entityType, entityId)` — no buildmyiq-svc change. Renders the discussion\n * as threads: every comment can be replied to (replies nest beneath their\n * parent, indentation capped so deep threads stay readable) and liked.\n * Posting and reacting are enforced by the workspace gateway's `@rbac`\n * directives on the conversations subgraph; a refused write shows its error\n * inline. Robust to empty state and errors.\n */\n\nimport type { FC } from 'react';\nimport { useState } from 'react';\nimport { MessageSquare, Reply, Send, ThumbsUp } from 'lucide-react';\nimport { Button, Textarea } from '@burdenoff/fe-libs/ui';\nimport { Section, LoadingView, ErrorView } from './StateViews';\nimport { EmptyState } from './EmptyState';\nimport { useBuildmyiq } from '../context';\nimport {\n countComments,\n likeState,\n useBuiComments,\n useBuiToggleCommentLike,\n useEcoCreateComment,\n type BuiCommentNode,\n} from '../hooks';\nimport { useTr } from '../shared/hooks/useTr';\nimport { cn } from '../utils/cn';\nimport { formatDateTime } from '../utils/formatters';\n\ninterface BuiDiscussionProps {\n entityType: string;\n entityId: string;\n title?: string;\n description?: string;\n}\n\n/** Replies deeper than this render at the same indentation as this level. */\nconst MAX_INDENT_DEPTH = 3;\n\nfunction displayName(user: ReturnType<typeof useBuildmyiq>['currentUser']): string {\n if (!user) return 'You';\n const full = [user.firstName, user.lastName].filter(Boolean).join(' ').trim();\n return user.name || full || user.username || user.email || 'You';\n}\n\nfunction initialFor(label: string): string {\n const trimmed = label.trim();\n return trimmed ? trimmed[0]!.toUpperCase() : '?';\n}\n\nconst errorText = (err: unknown, fallback: string): string =>\n err instanceof Error ? err.message : fallback;\n\n/**\n * A textarea + submit button, used for the root composer and inline replies.\n * Each composer tracks its own in-flight submission, so opening an inline reply\n * while a top-level comment is posting never re-enables that composer's submit\n * button (the comment mutation is shared, so its `isPending` cannot tell them apart).\n */\nconst Composer: FC<{\n initial: string;\n placeholder: string;\n ariaLabel: string;\n submitLabel: string;\n pendingLabel: string;\n /** Translated message shown when the post fails without an error message. */\n errorFallback: string;\n autoFocus?: boolean;\n onSubmit: (text: string) => Promise<void>;\n onCancel?: () => void;\n cancelLabel?: string;\n}> = ({\n initial,\n placeholder,\n ariaLabel,\n submitLabel,\n pendingLabel,\n errorFallback,\n autoFocus,\n onSubmit,\n onCancel,\n cancelLabel,\n}) => {\n const [draft, setDraft] = useState('');\n const [error, setError] = useState<string | null>(null);\n const [isPending, setIsPending] = useState(false);\n\n const submit = async (): Promise<void> => {\n const text = draft.trim();\n if (!text || isPending) return;\n setError(null);\n setIsPending(true);\n try {\n await onSubmit(text);\n setDraft('');\n } catch (err) {\n setError(errorText(err, errorFallback));\n } finally {\n setIsPending(false);\n }\n };\n\n return (\n <div className=\"flex gap-3\">\n <div className=\"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-action-primary-bg/15 text-sm font-semibold text-action-primary-bg\">\n {initial}\n </div>\n <div className=\"min-w-0 flex-1\">\n <Textarea\n value={draft}\n onChange={(e) => setDraft(e.target.value)}\n placeholder={placeholder}\n aria-label={ariaLabel}\n rows={2}\n autoFocus={autoFocus}\n />\n <div className=\"mt-2 flex items-center justify-end gap-2\">\n {error && (\n <span role=\"alert\" className=\"me-auto text-xs text-status-error-text\">\n {error}\n </span>\n )}\n {onCancel && (\n <Button size=\"sm\" variant=\"ghost\" onClick={onCancel} disabled={isPending}>\n {cancelLabel}\n </Button>\n )}\n <Button size=\"sm\" onClick={submit} disabled={!draft.trim() || isPending}>\n <Send className=\"me-1.5 h-4 w-4\" />\n {isPending ? pendingLabel : submitLabel}\n </Button>\n </div>\n </div>\n </div>\n );\n};\n\nexport function BuiDiscussion({\n entityType,\n entityId,\n title = 'Discussion',\n description = 'Coordinate review and verification with your team.',\n}: BuiDiscussionProps) {\n const { currentUser } = useBuildmyiq();\n const tr = useTr();\n const { data, isLoading, isError, refetch } = useBuiComments(entityType, entityId);\n const createComment = useEcoCreateComment(entityType, entityId);\n const toggleLike = useBuiToggleCommentLike(entityType, entityId);\n\n const [replyingTo, setReplyingTo] = useState<string | null>(null);\n const [likeError, setLikeError] = useState<string | null>(null);\n\n const selfName = displayName(currentUser);\n const userId = currentUser?.id;\n\n const authorLabel = (comment: BuiCommentNode): string =>\n userId && comment.authorId === userId\n ? selfName\n : tr('buildmyiq.discussion.workspaceMember', 'Workspace member');\n\n const threads = data?.threads ?? [];\n const total = countComments(threads);\n\n const handleLike = async (comment: BuiCommentNode, liked: boolean): Promise<void> => {\n setLikeError(null);\n try {\n await toggleLike.mutateAsync({ commentId: comment.id, like: !liked });\n } catch (err) {\n setLikeError(\n errorText(err, tr('buildmyiq.discussion.likeError', 'Could not update the like.'))\n );\n }\n };\n\n const renderComment = (comment: BuiCommentNode, depth: number) => {\n const label = authorLabel(comment);\n const body = comment.content.text ?? comment.content.markdown ?? '';\n const { count, likedByMe } = likeState(comment, userId);\n const likePending = toggleLike.isPending && toggleLike.variables?.commentId === comment.id;\n const nested = depth < MAX_INDENT_DEPTH;\n\n return (\n <li key={comment.id} className=\"flex flex-col gap-3\" data-testid=\"bui-discussion-comment\">\n <div className=\"flex gap-3\">\n <div className=\"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-bg-sunken text-sm font-semibold text-text-secondary\">\n {initialFor(label)}\n </div>\n <div className=\"min-w-0 flex-1\">\n <div className=\"flex flex-wrap items-baseline gap-x-2\">\n <span className=\"text-sm font-semibold text-text-primary\">{label}</span>\n <span className=\"text-xs text-text-tertiary\">\n {formatDateTime(comment.createdAt)}\n {comment.edited ? ` · ${tr('buildmyiq.discussion.edited', 'edited')}` : ''}\n </span>\n </div>\n <p className=\"mt-0.5 whitespace-pre-wrap break-words text-sm text-text-secondary\">\n {body}\n </p>\n <div className=\"mt-1.5 flex items-center gap-1\">\n <Button\n size=\"sm\"\n variant=\"ghost\"\n className={cn('h-7 px-2 text-xs', likedByMe && 'text-action-primary-bg')}\n aria-pressed={likedByMe}\n aria-label={\n likedByMe\n ? tr('buildmyiq.discussion.unlikeAria', 'Unlike comment')\n : tr('buildmyiq.discussion.likeAria', 'Like comment')\n }\n disabled={!userId || likePending}\n onClick={() => handleLike(comment, likedByMe)}\n >\n <ThumbsUp className={cn('me-1 h-3.5 w-3.5', likedByMe && 'fill-current')} />\n {count > 0 ? (\n <span className=\"tabular-nums\">{count}</span>\n ) : (\n tr('buildmyiq.discussion.like', 'Like')\n )}\n </Button>\n <Button\n size=\"sm\"\n variant=\"ghost\"\n className=\"h-7 px-2 text-xs\"\n aria-expanded={replyingTo === comment.id}\n onClick={() => setReplyingTo(replyingTo === comment.id ? null : comment.id)}\n >\n <Reply className=\"me-1 h-3.5 w-3.5 rtl:-scale-x-100\" />\n {tr('buildmyiq.discussion.reply', 'Reply')}\n </Button>\n </div>\n </div>\n </div>\n\n {(replyingTo === comment.id || comment.replies.length > 0) && (\n <div\n className={cn(\n 'flex flex-col gap-3',\n nested && 'ms-4 border-s border-border-seam ps-4 sm:ms-11'\n )}\n >\n {replyingTo === comment.id && (\n <Composer\n initial={initialFor(selfName)}\n placeholder={tr('buildmyiq.discussion.replyPlaceholder', 'Write a reply…')}\n ariaLabel={tr('buildmyiq.discussion.replyAria', 'Reply')}\n submitLabel={tr('buildmyiq.discussion.replyButton', 'Reply')}\n pendingLabel={tr('buildmyiq.discussion.posting', 'Posting…')}\n cancelLabel={tr('buildmyiq.discussion.cancel', 'Cancel')}\n errorFallback={tr('buildmyiq.discussion.postError', 'Failed to post comment.')}\n autoFocus\n onCancel={() => setReplyingTo(null)}\n onSubmit={async (text) => {\n await createComment.mutateAsync({ text, parentCommentId: comment.id });\n // Close only this composer: the learner may have opened another\n // reply while this one was posting, and that draft must survive.\n setReplyingTo((current) => (current === comment.id ? null : current));\n }}\n />\n )}\n {comment.replies.length > 0 && (\n <ul className=\"flex flex-col gap-4\">\n {comment.replies.map((reply) => renderComment(reply, depth + 1))}\n </ul>\n )}\n </div>\n )}\n </li>\n );\n };\n\n return (\n <Section title={title} description={description}>\n <div className=\"rounded-xl border border-border-seam bg-bg-surface/40 p-4\">\n <Composer\n initial={initialFor(selfName)}\n placeholder={tr('buildmyiq.discussion.placeholder', 'Add a comment for your team…')}\n ariaLabel={tr('buildmyiq.discussion.commentAria', 'Comment')}\n submitLabel={tr('buildmyiq.discussion.commentButton', 'Comment')}\n pendingLabel={tr('buildmyiq.discussion.posting', 'Posting…')}\n errorFallback={tr('buildmyiq.discussion.postError', 'Failed to post comment.')}\n onSubmit={async (text) => {\n await createComment.mutateAsync({ text });\n }}\n />\n\n <div className=\"mt-4 border-t border-border-seam pt-4\">\n {isLoading ? (\n <LoadingView label={tr('buildmyiq.discussion.loading', 'Loading discussion…')} />\n ) : isError ? (\n <ErrorView\n message={tr('buildmyiq.discussion.loadError', \"Couldn't load the discussion.\")}\n onRetry={() => refetch()}\n />\n ) : threads.length === 0 ? (\n <EmptyState\n illustration=\"empty-data\"\n icon={<MessageSquare className=\"h-9 w-9\" />}\n title={tr('buildmyiq.discussion.emptyTitle', 'No comments yet')}\n description={tr(\n 'buildmyiq.discussion.emptyDescription',\n 'Start the discussion by adding the first comment.'\n )}\n />\n ) : (\n <>\n <p className=\"mb-3 text-xs text-text-tertiary\">\n {tr(\n total === 1\n ? 'buildmyiq.discussion.countSingular'\n : 'buildmyiq.discussion.countPlural',\n total === 1 ? '{{n}} comment' : '{{n}} comments',\n { n: total }\n )}\n </p>\n {likeError && (\n <p role=\"alert\" className=\"mb-3 text-xs text-status-error-text\">\n {likeError}\n </p>\n )}\n <ul className=\"flex flex-col gap-4\">\n {threads.map((comment) => renderComment(comment, 0))}\n </ul>\n </>\n )}\n </div>\n </div>\n </Section>\n );\n}\n"],"mappings":";;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Ae,WAAU,UAAW,CAAA;KAC1C,OAAO,EAAG,mCAAmC,iBAAiB;KAC9D,aAAa,EACX,yCACA,mDACF;IACD,CAAA,IAED,kBAAA,GAAA,EAAA,UAAA;KACE,kBAAC,KAAD;MAAG,WAAU;gBACV,EACC,MAAU,IACN,uCACA,oCACJ,MAAU,IAAI,kBAAkB,kBAChC,EAAE,GAAG,EAAM,CACb;KACC,CAAA;KACF,KACC,kBAAC,KAAD;MAAG,MAAK;MAAQ,WAAU;gBACvB;KACA,CAAA;KAEL,kBAAC,MAAD;MAAI,WAAU;gBACX,EAAQ,KAAK,MAAY,EAAc,GAAS,CAAC,CAAC;KACjD,CAAA;IACJ,EAAA,CAAA;GAED,CAAA,CACF;;CACE,CAAA;AAEb"}
|
|
@@ -2,16 +2,29 @@
|
|
|
2
2
|
* Buildmyiq — wspace-conversations-svc EntityComment REUSE hooks (Integration B).
|
|
3
3
|
* @module buildmyiq/hooks/useBuiComments
|
|
4
4
|
*
|
|
5
|
-
* Adds a discussion surface to Buildmyiq entities WITHOUT any
|
|
6
|
-
* reusing the generic EntityComment API composed into
|
|
7
|
-
* Comments attach to any entity by
|
|
8
|
-
*
|
|
9
|
-
* - `
|
|
5
|
+
* Adds a threaded discussion surface to Buildmyiq entities WITHOUT any
|
|
6
|
+
* buildmyiq-svc change by reusing the generic EntityComment API composed into
|
|
7
|
+
* the WORKSPACE supergraph. Comments attach to any entity by
|
|
8
|
+
* `(entityType, entityId)`:
|
|
9
|
+
* - `getEntityComments(input): EntityCommentConnection!` — every comment on
|
|
10
|
+
* the entity (roots and replies); the thread tree is built client-side
|
|
11
|
+
* from `parentCommentId` (see `buildCommentTree`).
|
|
12
|
+
* - `createEntityComment(input)` — a root comment, or a reply when
|
|
13
|
+
* `parentCommentId` is set.
|
|
14
|
+
* - `addEntityCommentReaction` / `removeEntityCommentReaction` — the "like"
|
|
15
|
+
* reaction. The service always records the reaction for the authenticated
|
|
16
|
+
* actor, so no user id is sent.
|
|
10
17
|
*
|
|
11
18
|
* Transport reuses `wspaceFetch` from `useBuiFiles` (workspace gateway +
|
|
12
|
-
* workspace token).
|
|
13
|
-
* untouched.
|
|
19
|
+
* workspace token).
|
|
14
20
|
*/
|
|
21
|
+
/** The emoji stored for a "like" on a comment. */
|
|
22
|
+
export declare const LIKE_EMOJI = "\uD83D\uDC4D";
|
|
23
|
+
export interface BuiCommentReaction {
|
|
24
|
+
emoji: string;
|
|
25
|
+
count: number;
|
|
26
|
+
userIds: string[];
|
|
27
|
+
}
|
|
15
28
|
export interface BuiComment {
|
|
16
29
|
id: string;
|
|
17
30
|
authorId: string;
|
|
@@ -24,13 +37,40 @@ export interface BuiComment {
|
|
|
24
37
|
edited: boolean;
|
|
25
38
|
parentCommentId: string | null;
|
|
26
39
|
replyCount: number;
|
|
40
|
+
reactionSummary: BuiCommentReaction[];
|
|
41
|
+
}
|
|
42
|
+
/** A comment with its replies nested beneath it, oldest first at every level. */
|
|
43
|
+
export interface BuiCommentNode extends BuiComment {
|
|
44
|
+
replies: BuiCommentNode[];
|
|
27
45
|
}
|
|
28
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Nest a flat comment list into threads by `parentCommentId`. A reply whose
|
|
48
|
+
* parent is not in the list (deleted, or beyond the load ceiling) is shown as a
|
|
49
|
+
* root so it never silently disappears. Siblings are ordered oldest first.
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildCommentTree(comments: readonly BuiComment[]): BuiCommentNode[];
|
|
52
|
+
/** Likes on a comment and whether the given user is one of them. */
|
|
53
|
+
export declare function likeState(comment: Pick<BuiComment, 'reactionSummary'>, userId: string | undefined): {
|
|
54
|
+
count: number;
|
|
55
|
+
likedByMe: boolean;
|
|
56
|
+
};
|
|
57
|
+
/** Total comments in a thread tree (roots and every nested reply). */
|
|
58
|
+
export declare function countComments(nodes: readonly BuiCommentNode[]): number;
|
|
59
|
+
/** Every comment (roots and replies) on a Buildmyiq entity, nested into threads. */
|
|
29
60
|
export declare const useBuiComments: (entityType: string, entityId: string | undefined) => import('@tanstack/react-query').UseQueryResult<NoInfer<{
|
|
30
|
-
|
|
61
|
+
threads: BuiCommentNode[];
|
|
31
62
|
total: number;
|
|
32
63
|
}>, Error>;
|
|
64
|
+
/** Post a root comment, or a reply when `parentCommentId` is given. */
|
|
33
65
|
export declare const useEcoCreateComment: (entityType: string, entityId: string) => import('@tanstack/react-query').UseMutationResult<{
|
|
34
66
|
id: string;
|
|
35
|
-
}, Error, string
|
|
67
|
+
}, Error, string | {
|
|
68
|
+
text: string;
|
|
69
|
+
parentCommentId?: string;
|
|
70
|
+
}, unknown>;
|
|
71
|
+
/** Like or unlike a comment as the signed-in user. */
|
|
72
|
+
export declare const useBuiToggleCommentLike: (entityType: string, entityId: string) => import('@tanstack/react-query').UseMutationResult<boolean, Error, {
|
|
73
|
+
commentId: string;
|
|
74
|
+
like: boolean;
|
|
75
|
+
}, unknown>;
|
|
36
76
|
//# sourceMappingURL=useBuiComments.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBuiComments.d.ts","sourceRoot":"","sources":["../../../src/buildmyiq/hooks/useBuiComments.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"useBuiComments.d.ts","sourceRoot":"","sources":["../../../src/buildmyiq/hooks/useBuiComments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAQH,kDAAkD;AAClD,eAAO,MAAM,UAAU,iBAAO,CAAC;AAO/B,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;KACzB,CAAC;IACF,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,kBAAkB,EAAE,CAAC;CACvC;AAED,iFAAiF;AACjF,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B;AAQD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,SAAS,UAAU,EAAE,GAAG,cAAc,EAAE,CAYlF;AAED,oEAAoE;AACpE,wBAAgB,SAAS,CACvB,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,EAC5C,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAMvC;AAED,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,CAEtE;AAED,oFAAoF;AACpF,eAAO,MAAM,cAAc,GAAI,YAAY,MAAM,EAAE,UAAU,MAAM,GAAG,SAAS;;;UA+C9E,CAAC;AAEF,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,GAAI,YAAY,MAAM,EAAE,UAAU,MAAM;QAMN,MAAM;;UAF1B,MAAM;sBAAoB,MAAM;WAoB7E,CAAC;AAEF,sDAAsD;AACtD,eAAO,MAAM,uBAAuB,GAAI,YAAY,MAAM,EAAE,UAAU,MAAM;eAInB,MAAM;UAAQ,OAAO;WAsB7E,CAAC"}
|
|
@@ -4,43 +4,87 @@ import { invalidateAfterWrite as t } from "./invalidateAfterWrite.js";
|
|
|
4
4
|
import { wspaceFetch as n } from "./useBuiFiles.js";
|
|
5
5
|
import { useMutation as r, useQuery as i, useQueryClient as a } from "@tanstack/react-query";
|
|
6
6
|
//#region src/buildmyiq/hooks/useBuiComments.ts
|
|
7
|
-
var o = (e, t) => [
|
|
7
|
+
var o = "👍", s = 100, c = 500, l = (e, t) => [
|
|
8
8
|
"buildmyiq",
|
|
9
9
|
"comments",
|
|
10
10
|
e,
|
|
11
11
|
t
|
|
12
|
-
],
|
|
12
|
+
], u = (e, t) => new Date(e.createdAt).getTime() - new Date(t.createdAt).getTime();
|
|
13
|
+
function d(e) {
|
|
14
|
+
let t = /* @__PURE__ */ new Map();
|
|
15
|
+
for (let n of [...e].sort(u)) t.set(n.id, {
|
|
16
|
+
...n,
|
|
17
|
+
replies: []
|
|
18
|
+
});
|
|
19
|
+
let n = [];
|
|
20
|
+
for (let e of t.values()) {
|
|
21
|
+
let r = e.parentCommentId ? t.get(e.parentCommentId) : void 0;
|
|
22
|
+
r && r !== e ? r.replies.push(e) : n.push(e);
|
|
23
|
+
}
|
|
24
|
+
return n;
|
|
25
|
+
}
|
|
26
|
+
function f(e, t) {
|
|
27
|
+
let n = e.reactionSummary.find((e) => e.emoji === o);
|
|
28
|
+
return {
|
|
29
|
+
count: n?.count ?? 0,
|
|
30
|
+
likedByMe: !!(t && n?.userIds.includes(t))
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function p(e) {
|
|
34
|
+
return e.reduce((e, t) => e + 1 + p(t.replies), 0);
|
|
35
|
+
}
|
|
36
|
+
var m = (t, r) => {
|
|
13
37
|
let { apiGatewayUrl: a } = e();
|
|
14
38
|
return i({
|
|
15
|
-
queryKey:
|
|
39
|
+
queryKey: l(t, r ?? ""),
|
|
16
40
|
enabled: !!r,
|
|
17
41
|
queryFn: async () => {
|
|
18
|
-
let e =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
42
|
+
let e = [], i = 0;
|
|
43
|
+
for (let o = 0; o < c; o += s) {
|
|
44
|
+
let c = await n("query BuiGetEntityComments($input: GetCommentsInput!) {\n getEntityComments(input: $input) {\n total\n items {\n id\n authorId\n authorType\n content { text markdown }\n createdAt\n edited\n parentCommentId\n replyCount\n reactionSummary { emoji count userIds }\n }\n }\n }", { input: {
|
|
45
|
+
entityType: t,
|
|
46
|
+
entityId: r,
|
|
47
|
+
sortBy: "createdAt",
|
|
48
|
+
sortOrder: "asc",
|
|
49
|
+
skip: o,
|
|
50
|
+
take: s
|
|
51
|
+
} }, a);
|
|
52
|
+
if (i = c.getEntityComments.total, e.push(...c.getEntityComments.items), c.getEntityComments.items.length < s || e.length >= i) break;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
threads: d(e),
|
|
56
|
+
total: i
|
|
27
57
|
};
|
|
28
58
|
}
|
|
29
59
|
});
|
|
30
|
-
},
|
|
31
|
-
let { apiGatewayUrl:
|
|
60
|
+
}, h = (i, o) => {
|
|
61
|
+
let { apiGatewayUrl: s } = e(), c = a();
|
|
32
62
|
return r({
|
|
33
|
-
mutationFn: async (e) =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
63
|
+
mutationFn: async (e) => {
|
|
64
|
+
let { text: t, parentCommentId: r } = typeof e == "string" ? { text: e } : e;
|
|
65
|
+
return (await n("mutation BuiCreateEntityComment($input: CreateEntityCommentInput!) {\n createEntityComment(input: $input) { id }\n }", { input: {
|
|
66
|
+
entityType: i,
|
|
67
|
+
entityId: o,
|
|
68
|
+
content: { text: t },
|
|
69
|
+
...r ? { parentCommentId: r } : {}
|
|
70
|
+
} }, s)).createEntityComment;
|
|
71
|
+
},
|
|
72
|
+
onSuccess: () => t(c, l(i, o))
|
|
73
|
+
});
|
|
74
|
+
}, g = (i, s) => {
|
|
75
|
+
let { apiGatewayUrl: c } = e(), u = a();
|
|
76
|
+
return r({
|
|
77
|
+
mutationFn: async ({ commentId: e, like: t }) => (t ? await n("mutation BuiLikeComment($input: AddReactionInput!) {\n addEntityCommentReaction(input: $input) { id }\n }", { input: {
|
|
78
|
+
commentId: e,
|
|
79
|
+
emoji: o
|
|
80
|
+
} }, c) : await n("mutation BuiUnlikeComment($input: RemoveReactionInput!) {\n removeEntityCommentReaction(input: $input)\n }", { input: {
|
|
81
|
+
commentId: e,
|
|
82
|
+
emoji: o
|
|
83
|
+
} }, c), t),
|
|
84
|
+
onSuccess: () => t(u, l(i, s))
|
|
41
85
|
});
|
|
42
86
|
};
|
|
43
87
|
//#endregion
|
|
44
|
-
export {
|
|
88
|
+
export { o as LIKE_EMOJI, d as buildCommentTree, p as countComments, f as likeState, m as useBuiComments, g as useBuiToggleCommentLike, h as useEcoCreateComment };
|
|
45
89
|
|
|
46
90
|
//# sourceMappingURL=useBuiComments.js.map
|