@logora/debate 0.3.56 → 0.3.58

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.
@@ -1,9 +1,9 @@
1
- import { jsxs as _, jsx as i } from "react/jsx-runtime";
1
+ import { jsxs as _, jsx as o } from "react/jsx-runtime";
2
2
  import $e from "@rooks/use-sessionstorage-state";
3
3
  import { useRef as qe, useState as c, useEffect as M, Suspense as De, lazy as We } from "react";
4
- import { useIntl as Ye, FormattedMessage as ce } from "react-intl";
4
+ import { useIntl as Ye, FormattedMessage as me } from "react-intl";
5
5
  import { useLocation as ke } from "react-router";
6
- import w from "classnames";
6
+ import I from "classnames";
7
7
  import n from "./ArgumentInput.module.scss.js";
8
8
  import { useDataProvider as Re } from "../../data/data_provider/useDataProvider.js";
9
9
  import { useList as je } from "../../list/list_provider/useList.js";
@@ -20,156 +20,156 @@ import { Avatar as et } from "../../user/avatar/Avatar.js";
20
20
  import { AuthorBox as tt } from "../../user/author_box/AuthorBox.js";
21
21
  import { TextEditor as nt } from "../text_editor/TextEditor.js";
22
22
  import { Icon as at } from "../../icons/icon/Icon.js";
23
- const it = We(() => import("../../modal/side_modal/index.js").then((I) => ({ default: I.SideModal }))), Nt = ({
24
- argumentListId: I,
25
- avatarSize: me = 48,
23
+ const ot = We(() => import("../../modal/side_modal/index.js").then((v) => ({ default: v.SideModal }))), Nt = ({
24
+ argumentListId: v,
25
+ avatarSize: ge = 48,
26
26
  disabled: z = !1,
27
27
  positions: a = [],
28
28
  disabledPositions: S = [],
29
- groupId: v,
29
+ groupId: A,
30
30
  groupName: fe,
31
31
  groupType: O,
32
- hideSourceAction: ge = !1,
33
- isReply: d = !1,
32
+ hideSourceAction: he = !1,
33
+ isReply: u = !1,
34
34
  onSubmit: J,
35
- parentId: L,
36
- placeholder: he,
35
+ parentId: F,
36
+ placeholder: pe,
37
37
  positionId: b,
38
- focusOnInit: pe = !1,
39
- activeOnInit: F = !1,
38
+ focusOnInit: _e = !1,
39
+ activeOnInit: P = !1,
40
40
  userGuideUrl: K,
41
- hideUserGuideLink: _e = !1,
42
- hideCharCount: Me = !1,
43
- disableAutoActivate: ve = !1
41
+ hideUserGuideLink: Me = !1,
42
+ hideCharCount: ve = !1,
43
+ disableAutoActivate: Ae = !1
44
44
  }) => {
45
- const o = Ye(), G = Re(), x = je(), h = ze(), {
45
+ const r = Ye(), G = Re(), x = je(), h = ze(), {
46
46
  focus: H,
47
47
  setFocus: N,
48
48
  setReset: be,
49
- inputContent: P,
50
- setInputContent: Ae,
49
+ inputContent: B,
50
+ setInputContent: Q,
51
51
  setInputRichContent: Ce
52
- } = Oe(), { isLoggedIn: A, currentUser: u } = Je(), { errors: B, validate: E } = Ke(), { isMobile: m } = Ge(), we = ke(), Q = qe(null), [V, U] = c([]), [$, q] = c(""), [X, D] = c(null), [l, p] = c(null), [Z, ee] = c(null), [te, ne] = c(!1), [C, ae] = c(!1), [W, ie] = c({}), [f, Ie] = $e(
52
+ } = Oe(), { isLoggedIn: C, currentUser: d } = Je(), { errors: E, validate: V } = Ke(), { isMobile: m } = Ge(), we = ke(), X = qe(null), [U, $] = c([]), [q, D] = c(""), [Z, W] = c(null), [l, p] = c(null), [ee, te] = c(null), [ne, ae] = c(!1), [w, oe] = c(!1), [y, ie] = c({}), [g, Ie] = $e(
53
53
  "userSide",
54
54
  {}
55
- ), [g, Se] = c(
56
- !A && h?.actions?.disableInputForVisitor
55
+ ), [f, Se] = c(
56
+ !C && h?.actions?.disableInputForVisitor
57
57
  ), Y = He(), { showModal: xe } = Qe(), { toast: k } = Xe() || {}, se = new URLSearchParams(
58
58
  typeof window < "u" ? window.location.search : we.search
59
59
  );
60
60
  M(() => {
61
61
  Se(
62
- !A && h?.actions?.disableInputForVisitor
62
+ !C && h?.actions?.disableInputForVisitor
63
63
  );
64
- }, [A, h]);
65
- const R = u?.role === "editor" || u?.role === "moderator", oe = u?.moderation_status === "banned";
64
+ }, [C, h]);
65
+ const R = d?.role === "editor" || d?.role === "moderator", re = d?.moderation_status === "banned";
66
66
  M(() => {
67
67
  let e = null;
68
- typeof window < "u" && (e = se.get("positionId")), b && b != a[2]?.id && a?.find((t) => t.id === b) ? p(b) : e && e != a[2]?.id ? p(e) : f && f.groupId == v && f.positionId != a[2]?.id && p(f.positionId);
68
+ typeof window < "u" && (e = se.get("positionId")), b && b != a[2]?.id && a?.find((t) => t.id === b) ? p(b) : e && e != a[2]?.id ? p(e) : g && g.groupId == A && g.positionId != a[2]?.id && p(g.positionId);
69
69
  }, [b]), M(() => {
70
- F && (j(), N(!0));
71
- }, [F]), M(() => {
70
+ P && (j(), N(!0));
71
+ }, [P]), M(() => {
72
72
  if (typeof window < "u") {
73
- const e = pe || se.get("initArgument");
73
+ const e = _e || se.get("initArgument");
74
74
  (e === !0 || e === "true") && (N(!0), Ee());
75
75
  }
76
76
  }, []), M(() => {
77
- H && (re(), N(!1));
77
+ H && (ue(), N(!1));
78
78
  }, [H]), M(() => {
79
- P?.id && (Ne(P), N(!0));
80
- }, [P]);
79
+ B?.id && (Ne(B), N(!0));
80
+ }, [B]);
81
81
  const Ne = (e) => {
82
- ie(e), ae(!0), U(e.sources), q(e.content), D(e.rich_content), ee(e.id), re(), p(e.position?.id), JSON.parse(e.rich_content).hasOwnProperty("root") ? Ce(e.rich_content) : Ae(e.content);
83
- }, re = () => {
84
- Q.current.scrollIntoView(!1);
82
+ ie(e), oe(!0), $(e.sources), D(e.content), W(e.rich_content), te(e.id), ue(), p(e.position?.id), JSON.parse(e.rich_content).hasOwnProperty("root") ? Ce(e.rich_content) : Q(e.content);
83
+ }, ue = () => {
84
+ X.current.scrollIntoView(!1);
85
85
  }, de = () => {
86
- q(""), D(null), ie({}), ee(null), U([]), be(!0);
86
+ D(""), W(null), ie({}), te(null), $([]), be(!0), Q(null);
87
87
  }, ye = (e) => {
88
- p(e), le(e);
88
+ p(e), ce(e);
89
89
  }, Te = () => {
90
90
  xe(
91
- /* @__PURE__ */ i(De, { fallback: null, children: /* @__PURE__ */ i(
92
- it,
91
+ /* @__PURE__ */ o(De, { fallback: null, children: /* @__PURE__ */ o(
92
+ ot,
93
93
  {
94
- modalTitle: o.formatMessage({
94
+ modalTitle: r.formatMessage({
95
95
  id: "modal.side_modal.modal_title",
96
96
  defaultMessage: "Choose your side"
97
97
  }),
98
98
  onChooseSide: ye,
99
99
  positions: a,
100
100
  title: fe,
101
- disabledPositions: !d && S,
102
- isNeutral: f && f.groupId == v && f.positionId === a[2]?.id
101
+ disabledPositions: !u && S,
102
+ isNeutral: g && g.groupId == A && g.positionId === a[2]?.id
103
103
  }
104
104
  ) })
105
105
  );
106
106
  }, Le = () => {
107
- A ? Z ? Be() : !a || a?.length === 0 || !S?.find((e) => e?.id === l) && l || R && d ? le(d && R && a[0]?.id) : Te() : Y({ loginAction: "argument" });
107
+ C ? ee ? Be() : !a || a?.length === 0 || !S?.find((e) => e?.id === l) && l || R && u ? ce(u && R && a[0]?.id) : Te() : Y({ loginAction: "argument" });
108
108
  }, Fe = (e, t) => {
109
- g ? Y({ loginAction: "argument" }) : (q(e), D(t), E({ content: e }, [{ content: ["url", null] }]));
109
+ f ? Y({ loginAction: "argument" }) : (D(e), W(t), V({ content: e }, [{ content: ["url", null] }]));
110
110
  }, Pe = (e) => {
111
- U(e);
112
- }, ue = [
111
+ $(e);
112
+ }, le = [
113
113
  { content: ["length", 3] },
114
114
  { content: ["required", null] },
115
115
  { content: ["url", null] },
116
116
  ...!a || a?.length === 0 ? [] : [{ position_id: ["required", null] }]
117
- ], le = (e) => {
118
- const t = e || l, r = {
119
- content: $,
120
- rich_content: X,
121
- group_id: v,
117
+ ], ce = (e) => {
118
+ const t = e || l, s = {
119
+ content: q,
120
+ rich_content: Z,
121
+ group_id: A,
122
122
  ...O && { group_type: O },
123
123
  ...t && { position_id: t },
124
- is_reply: !!L,
125
- message_id: L || null,
126
- source_ids: V?.map((s) => s.id)
124
+ is_reply: !!F,
125
+ message_id: F || null,
126
+ source_ids: U?.map((i) => i.id)
127
127
  };
128
- E(r, ue) && (t && a && a.map((s) => s.id).includes(t) && Ie({
129
- groupId: v,
128
+ V(s, le) && (t && a && a.map((i) => i.id).includes(t) && Ie({
129
+ groupId: A,
130
130
  positionId: t
131
- }), de(), G.create("messages", r).then((s) => {
132
- if (s.data.success) {
133
- if (L)
134
- J(s.data.data.resource), k(
135
- o.formatMessage({
131
+ }), de(), G.create("messages", s).then((i) => {
132
+ if (i.data.success) {
133
+ if (F)
134
+ J(i.data.data.resource), k(
135
+ r.formatMessage({
136
136
  id: "alert.argument_create",
137
137
  defaultMessage: "Your contribution has been sent !"
138
138
  }),
139
139
  {
140
140
  type: "success",
141
- points: o.formatMessage({
141
+ points: r.formatMessage({
142
142
  id: "alert.reply_gain",
143
143
  defaultMessage: " "
144
144
  })
145
145
  }
146
146
  );
147
147
  else {
148
- const y = s.data.data.resource;
149
- let T = I;
150
- t && !m && (T = `argumentList${y.position.id}`), J?.(
151
- $,
148
+ const T = i.data.data.resource;
149
+ let L = v;
150
+ t && !m && (L = `argumentList${T.position.id}`), J?.(
151
+ q,
152
152
  a.find((Ue) => Ue.id === t) || null
153
- ), x.add(T, [y]), k(
154
- o.formatMessage({
153
+ ), x.add(L, [T]), k(
154
+ r.formatMessage({
155
155
  id: "alert.argument_create",
156
156
  defaultMessage: "Your contribution has been sent !"
157
157
  }),
158
158
  {
159
159
  type: "success",
160
- points: o.formatMessage({
160
+ points: r.formatMessage({
161
161
  id: "alert.argument_create_gain",
162
162
  defaultMessage: "Up to 10 eloquence points"
163
163
  }),
164
164
  category: "ARGUMENT",
165
- contentKey: u.messages_count === 2 ? "alert.third_argument" : "alert.first_argument"
165
+ contentKey: d.messages_count === 2 ? "alert.third_argument" : "alert.first_argument"
166
166
  }
167
167
  );
168
168
  }
169
169
  typeof window < "u" && window.dispatchEvent(
170
170
  new CustomEvent("logora:user_content:created", {
171
171
  detail: {
172
- content: s.data.data?.resource
172
+ content: i.data.data?.resource
173
173
  }
174
174
  })
175
175
  );
@@ -177,41 +177,42 @@ const it = We(() => import("../../modal/side_modal/index.js").then((I) => ({ def
177
177
  }));
178
178
  }, Be = () => {
179
179
  const e = {
180
- content: $,
181
- rich_content: X,
182
- source_ids: V?.map((t) => t.id),
180
+ content: q,
181
+ rich_content: Z,
182
+ source_ids: U?.map((t) => t.id),
183
183
  ...l && { position_id: l }
184
184
  };
185
- E(e, ue) && G.update("messages", Z, e).then((t) => {
185
+ V(e, le) && G.update("messages", ee, e).then((t) => {
186
186
  if (t.data.success) {
187
- const r = t.data.data.resource;
188
- let s = I;
189
- if (r.is_reply ? s = `argument_${r.reply_to_id || W?.reply_to_id}_reply_list` : l && !m && (s = `argumentList${r.position?.id}`), console.log("[updateArgument] listId:", s), W?.position?.id != r.position?.id && !m && !r.is_reply) {
190
- const y = `argumentList${W.position.id}`, T = `argumentList${r.position.id}`;
191
- x.remove(y, [r]), x.add(T, [r]);
187
+ const s = t.data.data.resource;
188
+ console.log("[updateArgument] réponse API:", s), console.log("[updateArgument] editElement:", y), console.log("[updateArgument] argumentListId prop:", v);
189
+ let i = v;
190
+ if (s.is_reply ? i = `argument_${s.reply_to_id || y?.reply_to_id}_reply_list` : l && !m && (i = `argumentList${s.position?.id}`), console.log("[updateArgument] listId final:", i), y?.position?.id != s.position?.id && !m && !s.is_reply) {
191
+ const T = `argumentList${y.position.id}`, L = `argumentList${s.position.id}`;
192
+ x.remove(T, [s]), x.add(L, [s]);
192
193
  } else
193
- x.update(s, [r]);
194
- k(o.formatMessage({ id: "alert.argument_modify" }), {
194
+ x.update(i, [s]);
195
+ k(r.formatMessage({ id: "alert.argument_modify" }), {
195
196
  type: "success"
196
197
  }), de();
197
198
  }
198
199
  });
199
200
  }, Ee = () => {
200
- if (!te) {
201
- ne(!0);
201
+ if (!ne) {
202
+ ae(!0);
202
203
  const e = setTimeout(() => {
203
- ne(!1);
204
+ ae(!1);
204
205
  }, 2e3);
205
206
  return () => clearTimeout(e);
206
207
  }
207
208
  }, j = () => {
208
- g ? Y({ loginAction: "argument" }) : ae(!0);
209
+ f ? Y({ loginAction: "argument" }) : oe(!0);
209
210
  }, Ve = () => {
210
211
  const e = S.find(
211
212
  (t) => t.id === l
212
213
  );
213
214
  if (e)
214
- return o.formatMessage(
215
+ return r.formatMessage(
215
216
  {
216
217
  id: "info.argument_side_limit",
217
218
  defaultMessage: "You have reached the argument limit (10) for position {position}."
@@ -220,27 +221,27 @@ const it = We(() => import("../../modal/side_modal/index.js").then((I) => ({ def
220
221
  );
221
222
  };
222
223
  return /* @__PURE__ */ _("div", { className: n.inputContainer, children: [
223
- z && /* @__PURE__ */ i("div", { className: n.disabledInputMask, children: oe ? o.formatMessage({
224
+ z && /* @__PURE__ */ o("div", { className: n.disabledInputMask, children: re ? r.formatMessage({
224
225
  id: "input.argument_input.user_banned",
225
226
  defaultMessage: "You are banned from the debate space."
226
- }) : o.formatMessage({
227
+ }) : r.formatMessage({
227
228
  id: "info.debate_is_inactive",
228
229
  defaultMessage: "Debate is closed"
229
230
  }) }),
230
- /* @__PURE__ */ i(
231
+ /* @__PURE__ */ o(
231
232
  "div",
232
233
  {
233
- className: w(n.argumentInput, {
234
- [n.flash]: te,
235
- [n.replyInputContainer]: d
234
+ className: I(n.argumentInput, {
235
+ [n.flash]: ne,
236
+ [n.replyInputContainer]: u
236
237
  }),
237
- children: /* @__PURE__ */ i("div", { "data-tid": "action_add_argument", ref: Q, children: /* @__PURE__ */ _("div", { className: n.argumentInputBox, children: [
238
- a.length > 0 && A && (!d || !R) && /* @__PURE__ */ _("div", { className: n.userPosition, children: [
239
- /* @__PURE__ */ i("div", { children: o.formatMessage({
238
+ children: /* @__PURE__ */ o("div", { "data-tid": "action_add_argument", ref: X, children: /* @__PURE__ */ _("div", { className: n.argumentInputBox, children: [
239
+ a.length > 0 && C && (!u || !R) && /* @__PURE__ */ _("div", { className: n.userPosition, children: [
240
+ /* @__PURE__ */ o("div", { children: r.formatMessage({
240
241
  id: "input.position",
241
242
  defaultMessage: "Your position"
242
243
  }) }),
243
- /* @__PURE__ */ i(
244
+ /* @__PURE__ */ o(
244
245
  Ze,
245
246
  {
246
247
  activeLabel: l === a[0].id ? 0 : l === a[1].id ? 1 : null,
@@ -253,32 +254,32 @@ const it = We(() => import("../../modal/side_modal/index.js").then((I) => ({ def
253
254
  /* @__PURE__ */ _(
254
255
  "div",
255
256
  {
256
- className: w(n.argumentTextInputBox, {
257
+ className: I(n.argumentTextInputBox, {
257
258
  [n.argumentTextInputBoxisTablet]: !m,
258
- [n.replyEditorRow]: d
259
+ [n.replyEditorRow]: u
259
260
  }),
260
261
  children: [
261
- /* @__PURE__ */ i(
262
+ /* @__PURE__ */ o(
262
263
  "div",
263
264
  {
264
- className: w(n.argumentAuthorContainer, {
265
+ className: I(n.argumentAuthorContainer, {
265
266
  [n.argumentAuthorContainerMobile]: m,
266
- [n.argumentAuthorContainerActivated]: !m && C || d
267
+ [n.argumentAuthorContainerActivated]: !m && w || u
267
268
  }),
268
- children: !m && C || d ? /* @__PURE__ */ i(
269
+ children: !m && w || u ? /* @__PURE__ */ o(
269
270
  et,
270
271
  {
271
- avatarUrl: u.image_url,
272
- userName: u.full_name,
273
- size: me
272
+ avatarUrl: d.image_url,
273
+ userName: d.full_name,
274
+ size: ge
274
275
  }
275
- ) : /* @__PURE__ */ i(
276
+ ) : /* @__PURE__ */ o(
276
277
  tt,
277
278
  {
278
- fullName: u?.full_name || o.formatMessage({ id: "default_author.full_name" }),
279
- avatarUrl: u?.image_url,
280
- points: u?.points || 0,
281
- slug: u?.hash_id
279
+ fullName: d?.full_name || r.formatMessage({ id: "default_author.full_name" }),
280
+ avatarUrl: d?.image_url,
281
+ points: d?.points || 0,
282
+ slug: d?.hash_id
282
283
  }
283
284
  )
284
285
  }
@@ -288,11 +289,11 @@ const it = We(() => import("../../modal/side_modal/index.js").then((I) => ({ def
288
289
  {
289
290
  onClick: j,
290
291
  "data-testid": "argument-input",
291
- className: w(n.textEditorBox, {
292
- [n.replyTextEditorBox]: d
292
+ className: I(n.textEditorBox, {
293
+ [n.replyTextEditorBox]: u
293
294
  }),
294
295
  children: [
295
- /* @__PURE__ */ i(
296
+ /* @__PURE__ */ o(
296
297
  nt,
297
298
  {
298
299
  handleChange: (e, t) => {
@@ -301,40 +302,40 @@ const it = We(() => import("../../modal/side_modal/index.js").then((I) => ({ def
301
302
  handleSourcesChange: (e) => {
302
303
  Pe(e);
303
304
  },
304
- placeholder: he,
305
- "aria-label": o.formatMessage({
305
+ placeholder: pe,
306
+ "aria-label": r.formatMessage({
306
307
  id: "input.argument_input.aria_label",
307
308
  defaultMessage: "Message input field"
308
309
  }),
309
310
  onSubmit: Le,
310
- sources: V,
311
- hideSourceAction: ge || g,
312
- uid: `Argument${v}`,
311
+ sources: U,
312
+ hideSourceAction: he || f,
313
+ uid: `Argument${A}`,
313
314
  onActivation: j,
314
- showStylesControls: C,
315
- disabled: z || g || oe,
316
- maxLength: g ? !1 : h?.actions?.argumentMaxLength,
317
- disableRichText: h?.actions?.disableRichText || g,
318
- shortBar: d,
319
- hideSubmit: g,
315
+ showStylesControls: w,
316
+ disabled: z || f || re,
317
+ maxLength: f ? !1 : h?.actions?.argumentMaxLength,
318
+ disableRichText: h?.actions?.disableRichText || f,
319
+ shortBar: u,
320
+ hideSubmit: f,
320
321
  allowedDomains: h?.allowed_sources,
321
- active: F,
322
- hideCharCount: Me,
323
- disableAutoActivate: ve
322
+ active: P,
323
+ hideCharCount: ve,
324
+ disableAutoActivate: Ae
324
325
  }
325
326
  ),
326
- B?.content && /* @__PURE__ */ i("div", { className: n.argumentInputWarning, children: B && Object.values(B).map((e, t) => /* @__PURE__ */ i("div", { children: e }, t)) }),
327
- C && S?.find(
327
+ E?.content && /* @__PURE__ */ o("div", { className: n.argumentInputWarning, children: E && Object.values(E).map((e, t) => /* @__PURE__ */ o("div", { children: e }, t)) }),
328
+ w && S?.find(
328
329
  (e) => e.id === l
329
330
  ) && /* @__PURE__ */ _(
330
331
  "div",
331
332
  {
332
- className: w(
333
+ className: I(
333
334
  n.argumentInputWarning,
334
335
  n.disabledPositionWarning
335
336
  ),
336
337
  children: [
337
- /* @__PURE__ */ i(
338
+ /* @__PURE__ */ o(
338
339
  at,
339
340
  {
340
341
  name: "announcement",
@@ -343,25 +344,25 @@ const it = We(() => import("../../modal/side_modal/index.js").then((I) => ({ def
343
344
  width: 20
344
345
  }
345
346
  ),
346
- /* @__PURE__ */ i("div", { className: n.argumentInputWarningText, children: Ve() })
347
+ /* @__PURE__ */ o("div", { className: n.argumentInputWarningText, children: Ve() })
347
348
  ]
348
349
  }
349
350
  ),
350
- C && K && !_e && /* @__PURE__ */ i("div", { className: n.guideMessage, children: /* @__PURE__ */ i(
351
- ce,
351
+ w && K && !Me && /* @__PURE__ */ o("div", { className: n.guideMessage, children: /* @__PURE__ */ o(
352
+ me,
352
353
  {
353
354
  id: "alert.guide_message",
354
355
  defaultMessage: "Contributions must comply with our {userCharter}.",
355
356
  values: {
356
- userCharter: /* @__PURE__ */ i(
357
+ userCharter: /* @__PURE__ */ o(
357
358
  "a",
358
359
  {
359
360
  className: n.guideMessage,
360
361
  href: K,
361
362
  target: "_blank",
362
363
  rel: "noreferrer",
363
- children: /* @__PURE__ */ i(
364
- ce,
364
+ children: /* @__PURE__ */ o(
365
+ me,
365
366
  {
366
367
  id: "alert.user_charter",
367
368
  defaultMessage: "user charter"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logora/debate",
3
- "version": "0.3.56",
3
+ "version": "0.3.58",
4
4
  "type": "module",
5
5
  "license": "AGPL-3.0",
6
6
  "description": "Design system of @Logora made with React",