@logora/debate 0.4.59 → 0.4.61

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,41 +1,46 @@
1
- import { makeStorage as u } from "./AuthStorage.js";
2
- const m = (a, k, f) => {
3
- const c = u(f), i = () => c.getToken(), d = () => {
4
- c.removeToken();
5
- }, _ = (e, s) => {
1
+ import { makeStorage as g } from "./AuthStorage.js";
2
+ const y = (i, k, _) => {
3
+ const a = g(_), l = () => a.getToken(), d = () => {
4
+ a.removeToken();
5
+ }, f = (e, r) => {
6
6
  const t = {
7
7
  ...e,
8
8
  expires_at: e.created_at + e.expires_in,
9
- session_id: s
9
+ session_id: r
10
10
  };
11
- c.setToken(t);
12
- }, T = (e) => {
13
- const s = e.session_id;
14
- return new Promise((t, r) => a.post(k, e).then((n) => {
11
+ a.setToken(t);
12
+ };
13
+ let s = null;
14
+ const h = (e) => {
15
+ if (s) return s;
16
+ const r = e.session_id, t = new Promise((c, u) => i.post(k, e).then((n) => {
15
17
  if (n.data.access_token) {
16
- const h = n.data;
17
- _(h, s), t(n);
18
+ const T = n.data;
19
+ f(T, r), c(n);
18
20
  } else
19
- r(n);
21
+ u(n);
20
22
  }).catch((n) => {
21
- r(n);
22
- }));
23
+ u(n);
24
+ })).finally(() => {
25
+ s = null;
26
+ });
27
+ return s = t, t;
23
28
  };
24
29
  let o = null;
25
30
  return {
26
- getToken: i,
31
+ getToken: l,
27
32
  removeToken: d,
28
- fetchToken: T,
33
+ fetchToken: h,
29
34
  refreshToken: () => {
30
35
  if (o) return o;
31
- const e = i(), s = {
36
+ const e = l(), r = {
32
37
  grant_type: "refresh_token",
33
38
  refresh_token: e.refresh_token
34
39
  };
35
- return o = a.post(k, s).then((t) => {
40
+ return o = i.post(k, r).then((t) => {
36
41
  if (t.data.access_token) {
37
- const r = t.data;
38
- return _(r, e.session_id), r.access_token;
42
+ const c = t.data;
43
+ return f(c, e.session_id), c.access_token;
39
44
  }
40
45
  return Promise.reject(t);
41
46
  }).finally(() => {
@@ -45,5 +50,5 @@ const m = (a, k, f) => {
45
50
  };
46
51
  };
47
52
  export {
48
- m as authTokenHandler
53
+ y as authTokenHandler
49
54
  };
@@ -17,9 +17,8 @@ const D = ({
17
17
  b(() => {
18
18
  const e = r.current;
19
19
  if (!e) return;
20
- e.open || e.showModal(), e.focus();
21
20
  const p = document.documentElement.style.overflow, y = document.body.style.overflow;
22
- return document.documentElement.style.overflow = "hidden", document.body.style.overflow = "hidden", () => {
21
+ return document.documentElement.style.overflow = "hidden", document.body.style.overflow = "hidden", e.open || e.showModal(), e.focus(), () => {
23
22
  document.documentElement.style.overflow = p, document.body.style.overflow = y, e.open && e.close();
24
23
  };
25
24
  }, []);
@@ -1,31 +1,31 @@
1
- import { jsxs as p, jsx as e } from "react/jsx-runtime";
2
- import { Suspense as M } from "react";
3
- import { useIntl as x } from "react-intl";
1
+ import { jsxs as M, jsx as e } from "react/jsx-runtime";
2
+ import { Suspense as x } from "react";
3
+ import { useIntl as _ } from "react-intl";
4
4
  import a from "./SuggestionVoteBox.module.scss.js";
5
- import { useAuth as _ } from "../../auth/use_auth/useAuth.js";
6
- import { useVote as b } from "../use_vote/useVote.js";
7
- import { useModal as w } from "../../dialog/modal/useModal.js";
5
+ import { useAuth as w } from "../../auth/use_auth/useAuth.js";
6
+ import { useVote as y } from "../use_vote/useVote.js";
7
+ import { useModal as C } from "../../dialog/modal/useModal.js";
8
8
  import { Button as r } from "../../action/button/Button.js";
9
- import { Icon as l } from "../../icons/icon/Icon.js";
10
- import { ConfirmModal as y } from "../../dialog/confirm_modal/ConfirmModal.js";
11
- const A = ({
12
- voteableType: u,
13
- voteableId: d,
9
+ import { Icon as d } from "../../icons/icon/Icon.js";
10
+ import { ConfirmModal as I } from "../../dialog/confirm_modal/ConfirmModal.js";
11
+ const Y = ({
12
+ voteableType: l,
13
+ voteableId: u,
14
14
  totalUpvote: m = 0,
15
- totalDownvote: f = 0,
16
- onVote: c,
17
- disabled: o = !1
15
+ totalDownvote: c = 0,
16
+ onVote: f,
17
+ disabled: g = !1
18
18
  }) => {
19
- const t = x(), { isLoggedIn: g } = _(), { activeVote: s, voteSide: n, handleVote: i } = b(
19
+ const t = _(), { isLoggedIn: h } = w(), { activeVote: s, voteSide: i, handleVote: n, voteLoading: v } = y(
20
+ l,
20
21
  u,
21
- d,
22
22
  m,
23
- f,
24
- c
25
- ), { showModal: h } = w(), v = () => {
26
- g && (s && !n ? i(!1) : h(
27
- /* @__PURE__ */ e(M, { fallback: null, children: /* @__PURE__ */ e(
28
- y,
23
+ c,
24
+ f
25
+ ), { showModal: p } = C(), o = g || v, b = () => {
26
+ h && (s && !i ? n(!1) : p(
27
+ /* @__PURE__ */ e(x, { fallback: null, children: /* @__PURE__ */ e(
28
+ I,
29
29
  {
30
30
  title: t.formatMessage({
31
31
  id: "vote.suggestion_vote_box.downvote",
@@ -43,21 +43,21 @@ const A = ({
43
43
  id: "info.no",
44
44
  defaultMessage: "No"
45
45
  }),
46
- onConfirmCallback: () => i(!1)
46
+ onConfirmCallback: () => n(!1)
47
47
  }
48
48
  ) })
49
49
  ));
50
50
  };
51
- return /* @__PURE__ */ p("div", { className: a.voteButtonsContainer, children: [
51
+ return /* @__PURE__ */ M("div", { className: a.voteButtonsContainer, children: [
52
52
  /* @__PURE__ */ e(
53
53
  r,
54
54
  {
55
55
  type: "button",
56
- onClick: o ? null : () => i(!0),
56
+ onClick: o ? null : () => n(!0),
57
57
  "data-testid": "upvote-button",
58
58
  disabled: o,
59
59
  rightIcon: /* @__PURE__ */ e(
60
- l,
60
+ d,
61
61
  {
62
62
  name: "check",
63
63
  width: 20,
@@ -66,7 +66,7 @@ const A = ({
66
66
  "aria-hidden": "true"
67
67
  }
68
68
  ),
69
- active: !(s && n),
69
+ active: !(s && i),
70
70
  children: /* @__PURE__ */ e("span", { className: a.text, children: t.formatMessage({
71
71
  id: "vote.suggestion_vote_box.upvote",
72
72
  defaultMessage: "I'm interested"
@@ -77,10 +77,10 @@ const A = ({
77
77
  r,
78
78
  {
79
79
  type: "button",
80
- onClick: o ? null : () => v(),
80
+ onClick: o ? null : () => b(),
81
81
  disabled: o,
82
- rightIcon: /* @__PURE__ */ e(l, { name: "close", width: 10, height: 10, "aria-hidden": "true" }),
83
- active: !(s && !n),
82
+ rightIcon: /* @__PURE__ */ e(d, { name: "close", width: 10, height: 10, "aria-hidden": "true" }),
83
+ active: !(s && !i),
84
84
  children: /* @__PURE__ */ e("span", { className: a.text, children: t.formatMessage({
85
85
  id: "vote.suggestion_vote_box.downvote",
86
86
  defaultMessage: "Not interested"
@@ -90,5 +90,5 @@ const A = ({
90
90
  ] });
91
91
  };
92
92
  export {
93
- A as SuggestionVoteBox
93
+ Y as SuggestionVoteBox
94
94
  };
@@ -1,74 +1,74 @@
1
1
  import { jsxs as a, jsx as o } from "react/jsx-runtime";
2
- import l from "classnames";
2
+ import d from "classnames";
3
3
  import "react";
4
- import { useIntl as w } from "react-intl";
4
+ import { useIntl as x } from "react-intl";
5
5
  import e from "./UpDownVoteBox.module.scss.js";
6
- import { useVote as x } from "../use_vote/useVote.js";
7
- import { Icon as d } from "../../icons/icon/Icon.js";
8
- const j = ({
9
- voteableType: p,
10
- voteableId: v,
11
- totalUpvote: m = 0,
12
- totalDownvote: c = 0,
13
- disabled: t = !1,
14
- hideDownvotes: u = !1
6
+ import { useVote as g } from "../use_vote/useVote.js";
7
+ import { Icon as r } from "../../icons/icon/Icon.js";
8
+ const k = ({
9
+ voteableType: v,
10
+ voteableId: p,
11
+ totalUpvote: c = 0,
12
+ totalDownvote: m = 0,
13
+ disabled: u = !1,
14
+ hideDownvotes: f = !1
15
15
  }) => {
16
- const { totalUpvotes: f, totalDownvotes: h, activeVote: s, voteSide: n, handleVote: i } = x(p, v, m, c), r = w();
16
+ const { totalUpvotes: h, totalDownvotes: b, activeVote: s, voteSide: i, handleVote: n, voteLoading: w } = g(v, p, c, m), l = x(), t = u || w;
17
17
  return /* @__PURE__ */ a("div", { className: e.container, children: [
18
18
  /* @__PURE__ */ a(
19
19
  "div",
20
20
  {
21
- className: l(e.upvoteContainer, {
21
+ className: d(e.upvoteContainer, {
22
22
  [e.disabled]: t,
23
- [e.active]: s && n
23
+ [e.active]: s && i
24
24
  }),
25
- onClick: t ? null : () => i(!0),
25
+ onClick: t ? null : () => n(!0),
26
26
  "data-testid": "upvote-button",
27
27
  children: [
28
28
  /* @__PURE__ */ o(
29
- d,
29
+ r,
30
30
  {
31
31
  name: "upvote",
32
32
  width: 27,
33
33
  height: 25,
34
- "aria-label": r.formatMessage({
34
+ "aria-label": l.formatMessage({
35
35
  id: "vote.up_down_vote_box.supporters",
36
36
  defaultMessage: "supporters"
37
37
  })
38
38
  }
39
39
  ),
40
- /* @__PURE__ */ o("div", { className: e.voteText, children: f })
40
+ /* @__PURE__ */ o("div", { className: e.voteText, children: h })
41
41
  ]
42
42
  }
43
43
  ),
44
44
  /* @__PURE__ */ a(
45
45
  "div",
46
46
  {
47
- className: l(e.downvoteContainer, {
47
+ className: d(e.downvoteContainer, {
48
48
  [e.disabled]: t,
49
- [e.active]: s && !n
49
+ [e.active]: s && !i
50
50
  }),
51
- onClick: t ? null : () => i(!1),
51
+ onClick: t ? null : () => n(!1),
52
52
  "data-testid": "downvote-button",
53
53
  children: [
54
54
  /* @__PURE__ */ o(
55
- d,
55
+ r,
56
56
  {
57
57
  name: "downvote",
58
58
  width: 27,
59
59
  height: 25,
60
- "aria-label": r.formatMessage({
60
+ "aria-label": l.formatMessage({
61
61
  id: "vote.up_down_vote_box.opponents",
62
62
  defaultMessage: "opponents"
63
63
  })
64
64
  }
65
65
  ),
66
- !u && /* @__PURE__ */ o("div", { className: e.voteText, children: h })
66
+ !f && /* @__PURE__ */ o("div", { className: e.voteText, children: b })
67
67
  ]
68
68
  }
69
69
  )
70
70
  ] });
71
71
  };
72
72
  export {
73
- j as UpDownVoteBox
73
+ k as UpDownVoteBox
74
74
  };
@@ -1,46 +1,46 @@
1
- import { useContext as B, useState as n, useEffect as E } from "react";
2
- import { VoteContext as H } from "../vote_provider/VoteProvider.js";
3
- import { useAuth as I } from "../../auth/use_auth/useAuth.js";
4
- import { useDataProvider as L } from "../../data/data_provider/useDataProvider.js";
5
- import { useAuthRequired as O } from "../../hooks/use_auth_required/useAuthRequired.js";
6
- const K = (x, d, S, q, w = null) => {
7
- const { votes: f } = B(H), { isLoggedIn: i } = I(), V = L(), [D, h] = n(!1), [A, T] = n(!0), [_, m] = n(), [r, g] = n(S), [u, v] = n(q), [y, s] = n(!1), [C, b] = n(!1), j = O();
8
- E(() => {
9
- if (!C && i && Object.keys(f).length > 0 && d in f) {
1
+ import { useContext as H, useState as n, useEffect as I } from "react";
2
+ import { VoteContext as O } from "../vote_provider/VoteProvider.js";
3
+ import { useAuth as P } from "../../auth/use_auth/useAuth.js";
4
+ import { useDataProvider as R } from "../../data/data_provider/useDataProvider.js";
5
+ import { useAuthRequired as z } from "../../hooks/use_auth_required/useAuthRequired.js";
6
+ const W = (x, d, L, S, v = null) => {
7
+ const { votes: f, voteableIds: w, votesLoading: q } = H(O), { isLoggedIn: i } = P(), V = R(), A = Array.isArray(w) && w.includes(d) && q, [T, h] = n(!1), [D, g] = n(!0), [b, m] = n(), [l, _] = n(L), [u, y] = n(S), [C, s] = n(!1), [j, k] = n(!1), B = z();
8
+ I(() => {
9
+ if (!j && i && Object.keys(f).length > 0 && d in f) {
10
10
  const e = f[d];
11
- b(!0), h(!!e), T(e?.is_upvote), m(e?.id);
11
+ k(!0), h(!!e), g(e?.is_upvote), m(e?.id);
12
12
  }
13
13
  }, [f, i]);
14
- const c = (e) => {
15
- h(!0), T(e);
16
- const t = e ? r + 1 : r, o = e ? u : u + 1;
17
- w?.(e, !0, t, o), e ? g((a) => a + 1) : v((a) => a + 1);
18
- }, l = (e) => {
14
+ const r = (e) => {
15
+ h(!0), g(e);
16
+ const t = e ? l + 1 : l, o = e ? u : u + 1;
17
+ v?.(e, !0, t, o), e ? _((a) => a + 1) : y((a) => a + 1);
18
+ }, c = (e) => {
19
19
  h(!1);
20
- const t = e ? r - 1 : r, o = e ? u : u - 1;
21
- w?.(e, !1, t, o), e ? g((a) => a - 1) : v((a) => a - 1);
22
- }, k = (e) => {
23
- if (b(!0), D)
24
- if (A === e)
25
- l(e), s(!0), V.delete("votes", _).then(
20
+ const t = e ? l - 1 : l, o = e ? u : u - 1;
21
+ v?.(e, !1, t, o), e ? _((a) => a - 1) : y((a) => a - 1);
22
+ }, E = (e) => {
23
+ if (k(!0), T)
24
+ if (D === e)
25
+ c(e), s(!0), V.delete("votes", b).then(
26
26
  (t) => {
27
- t.data?.success ? m(null) : c(e), s(!1);
27
+ t.data?.success ? m(null) : r(e), s(!1);
28
28
  },
29
29
  (t) => {
30
- c(e), s(!1);
30
+ r(e), s(!1);
31
31
  }
32
32
  );
33
33
  else {
34
- l(!e), c(e);
34
+ c(!e), r(e);
35
35
  const t = {
36
36
  is_upvote: e
37
37
  };
38
- s(!0), V.update("votes", _, t).then(
38
+ s(!0), V.update("votes", b, t).then(
39
39
  (o) => {
40
- o.data?.success || (l(e), c(!e)), s(!1);
40
+ o.data?.success || (c(e), r(!e)), s(!1);
41
41
  },
42
42
  (o) => {
43
- l(e), c(!e), s(!1);
43
+ c(e), r(!e), s(!1);
44
44
  }
45
45
  );
46
46
  }
@@ -50,26 +50,27 @@ const K = (x, d, S, q, w = null) => {
50
50
  voteable_type: x,
51
51
  is_upvote: e
52
52
  };
53
- c(e), s(!0), V.create("votes", t).then(
53
+ r(e), s(!0), V.create("votes", t).then(
54
54
  (o) => {
55
- o.data?.success ? m(o.data.data.resource.id) : l(e), s(!1);
55
+ o.data?.success ? m(o.data.data.resource.id) : c(e), s(!1);
56
56
  },
57
57
  (o) => {
58
- l(e), s(!1);
58
+ c(e), s(!1);
59
59
  }
60
60
  );
61
61
  }
62
62
  };
63
63
  return {
64
- totalUpvotes: r,
64
+ totalUpvotes: l,
65
65
  totalDownvotes: u,
66
- activeVote: D,
67
- voteSide: A,
66
+ activeVote: T,
67
+ voteSide: D,
68
68
  handleVote: (e) => {
69
- y || (i ? k(e) : j({ loginAction: "vote" }));
70
- }
69
+ !C && !A && (i ? E(e) : B({ loginAction: "vote" }));
70
+ },
71
+ voteLoading: A
71
72
  };
72
73
  };
73
74
  export {
74
- K as useVote
75
+ W as useVote
75
76
  };
@@ -1,17 +1,17 @@
1
1
  import { jsx as s, Fragment as pe, jsxs as l } from "react/jsx-runtime";
2
2
  import P from "@rooks/use-sessionstorage-state";
3
3
  import d from "classnames";
4
- import { useState as b, useEffect as L } from "react";
5
- import { useIntl as _e, FormattedMessage as m } from "react-intl";
4
+ import { useState as b, useEffect as k } from "react";
5
+ import { useIntl as _e, FormattedMessage as f } from "react-intl";
6
6
  import { useLocation as be } from "react-router";
7
7
  import o from "./VoteBox.module.scss.js";
8
- import { useTranslatedContent as k } from "../../translation/translated_content/useTranslatedContent.js";
8
+ import { useTranslatedContent as T } from "../../translation/translated_content/useTranslatedContent.js";
9
9
  import { useToast as Ne } from "../../dialog/toast_provider/useToast.js";
10
10
  import { useAuthRequired as Se } from "../../hooks/use_auth_required/useAuthRequired.js";
11
11
  import { useDataProvider as we } from "../../data/data_provider/useDataProvider.js";
12
12
  import { useConfig as Be } from "../../data/config_provider/useConfig.js";
13
13
  import { useAuth as Ce } from "../../auth/use_auth/useAuth.js";
14
- import { Icon as T } from "../../icons/icon/Icon.js";
14
+ import { Icon as j } from "../../icons/icon/Icon.js";
15
15
  import { ProgressBar as xe } from "../../progress/progress_bar/ProgressBar.js";
16
16
  import { Link as Ve } from "../../action/link/Link.js";
17
17
  import { Button as Me } from "../../action/button/Button.js";
@@ -21,35 +21,35 @@ const We = ({
21
21
  voteableType: v,
22
22
  voteableId: h,
23
23
  redirectUrl: S,
24
- displayColumn: j,
24
+ displayColumn: O,
25
25
  textAlignLeft: ee,
26
26
  showTotal: te = !0,
27
- voteBoxClassName: O,
28
- buttonContainerClassName: F,
29
- buttonClassName: E,
30
- showResultClassName: I,
27
+ voteBoxClassName: F,
28
+ buttonContainerClassName: E,
29
+ buttonClassName: I,
30
+ showResultClassName: U,
31
31
  onVote: w,
32
- disabled: M = !1,
32
+ disabled: A = !1,
33
33
  showVotesCommentsNumber: oe = !1,
34
34
  commentsCount: se,
35
- hideShowResultButton: U = !1
35
+ hideShowResultButton: H = !1
36
36
  }) => {
37
- const [H, g] = b(!0), [c, A] = b(void 0), [p, f] = b(!1), [u, ae] = b(
37
+ const [B, g] = b(!0), [c, y] = b(void 0), [p, m] = b(!1), [u, ae] = b(
38
38
  Number.parseFloat(N.total) || Object.values(N).reduce(
39
39
  (e, t) => e + Number.parseFloat(t),
40
40
  0
41
41
  ) || 0
42
- ), $ = k(
42
+ ), $ = T(
43
43
  r[0]?.name,
44
44
  r[0]?.language,
45
45
  "name",
46
46
  r[0]?.translation_entries
47
- ), q = k(
47
+ ), q = T(
48
48
  r[1]?.name,
49
49
  r[1]?.language,
50
50
  "name",
51
51
  r[1]?.translation_entries
52
- ), Y = k(
52
+ ), Y = T(
53
53
  r[2]?.name,
54
54
  r[2]?.language,
55
55
  "name",
@@ -67,15 +67,15 @@ const We = ({
67
67
  )
68
68
  }
69
69
  ), e;
70
- }, [i, W] = b(ce()), z = Se(), le = be(), y = we(), J = Be(), B = _e(), { isLoggedIn: C, isLoggingIn: K } = Ce();
71
- L(() => {
72
- K === !1 && (C ? ue(h) : g(!1));
73
- }, [K, C]), L(() => {
74
- if (H === !1 && !S) {
70
+ }, [i, W] = b(ce()), z = Se(), le = be(), R = we(), J = Be(), C = _e(), { isLoggedIn: x, isLoggingIn: K } = Ce();
71
+ k(() => {
72
+ K === !1 && (x ? ue(h) : g(!1));
73
+ }, [K, x]), k(() => {
74
+ if (B === !1 && !S) {
75
75
  const [e, t] = de();
76
- e && (t ? X(t) : f(!0));
76
+ e && (t ? X(t) : m(!0));
77
77
  }
78
- }, [H]), L(() => {
78
+ }, [B]), k(() => {
79
79
  w && w(c);
80
80
  }, [c]);
81
81
  const de = () => {
@@ -86,12 +86,12 @@ const We = ({
86
86
  ), t = !!e.get("initVote"), a = Number.parseInt(e.get("positionId")) || !1;
87
87
  return [t, a];
88
88
  }, ue = (e) => {
89
- g(!0), w && w(c), y.getOneWithToken("votes", `${v.toLowerCase()}/${e}`, {}).then((t) => {
90
- t.data.data.resource ? (A(t.data.data.resource), f(!0), g(!1)) : (g(!1), f(!1));
89
+ g(!0), w && w(c), R.getOneWithToken("votes", `${v.toLowerCase()}/${e}`, {}).then((t) => {
90
+ t.data.data.resource ? (y(t.data.data.resource), m(!0), g(!1)) : (g(!1), m(!1));
91
91
  }).catch((t) => {
92
92
  g(!1);
93
93
  });
94
- }, x = (e, t) => t === 0 ? 0 : Math.round(100 * (e / t)), me = (e) => {
94
+ }, V = (e, t) => t === 0 ? 0 : Math.round(100 * (e / t)), fe = (e) => {
95
95
  const t = {
96
96
  voteable_id: h,
97
97
  voteable_type: v || "Group",
@@ -101,36 +101,36 @@ const We = ({
101
101
  groupId: h,
102
102
  voteableType: v,
103
103
  positionId: e
104
- }), c ? (ve(e, c.position_id), p === !1 && R(), e !== c.position_id && y.update("votes", c.id, t).then((n) => {
105
- n.data.success && (A(n.data.data.resource), G(
106
- B.formatMessage({
104
+ }), c ? (ve(e, c.position_id), p === !1 && L(), e !== c.position_id && R.update("votes", c.id, t).then((n) => {
105
+ n.data.success && (y(n.data.data.resource), G(
106
+ C.formatMessage({
107
107
  id: "header.vote_confirm_modal",
108
108
  defaultMessage: "Your vote has been saved !"
109
109
  }),
110
110
  { type: "success" }
111
111
  ));
112
- })) : (fe(e), R(), y.create("votes", t).then((n) => {
113
- n.data.success && (A(n.data.data.resource), G(
114
- B.formatMessage({
112
+ })) : (me(e), L(), R.create("votes", t).then((n) => {
113
+ n.data.success && (y(n.data.data.resource), G(
114
+ C.formatMessage({
115
115
  id: "header.vote_confirm_modal",
116
116
  defaultMessage: "Your vote has been saved !"
117
117
  }),
118
118
  { type: "success" }
119
119
  ));
120
120
  }));
121
- }, fe = (e) => {
121
+ }, me = (e) => {
122
122
  const t = i[e].count + 1, a = u + 1, n = {};
123
- r.forEach((V) => {
124
- if (e === V.id)
125
- n[V.id] = {
123
+ r.forEach((M) => {
124
+ if (e === M.id)
125
+ n[M.id] = {
126
126
  count: t,
127
- percentage: x(t, a)
127
+ percentage: V(t, a)
128
128
  };
129
129
  else {
130
- const Z = i[V.id].count;
131
- n[V.id] = {
130
+ const Z = i[M.id].count;
131
+ n[M.id] = {
132
132
  count: Z,
133
- percentage: x(Z, a)
133
+ percentage: V(Z, a)
134
134
  };
135
135
  }
136
136
  }), W(n), ae(a);
@@ -140,14 +140,14 @@ const We = ({
140
140
  ...i,
141
141
  [t]: {
142
142
  count: i[t].count - 1,
143
- percentage: x(
143
+ percentage: V(
144
144
  i[t].count - 1,
145
145
  u
146
146
  )
147
147
  },
148
148
  [e]: {
149
149
  count: i[e].count + 1,
150
- percentage: x(
150
+ percentage: V(
151
151
  i[e].count + 1,
152
152
  u
153
153
  )
@@ -162,13 +162,13 @@ const We = ({
162
162
  });
163
163
  return S + `?${t.toString()}`;
164
164
  }, X = (e) => {
165
- C ? Object.keys(i).includes(e.toString()) && (me(e), D()) : (Object.keys(i).includes(e.toString()) && ne({
165
+ B || (x ? Object.keys(i).includes(e.toString()) && (fe(e), D()) : (Object.keys(i).includes(e.toString()) && ne({
166
166
  groupId: h,
167
167
  voteableType: v,
168
168
  positionId: e
169
- }), z({ loginAction: "vote" }));
170
- }, R = () => {
171
- p && ie(), f(!p);
169
+ }), z({ loginAction: "vote" })));
170
+ }, L = () => {
171
+ p && ie(), m(!p);
172
172
  }, he = (e, t) => {
173
173
  let a;
174
174
  t === 0 ? a = $.translatedContent : t === 1 ? a = q.translatedContent : t === 2 && (a = Y.translatedContent);
@@ -187,10 +187,10 @@ const We = ({
187
187
  title: a,
188
188
  className: d(o.voteButton, {
189
189
  [o.textAlignLeft]: ee,
190
- [E]: E
190
+ [I]: I
191
191
  }),
192
192
  onClick: n ? () => X(e.id) : null,
193
- disabled: M,
193
+ disabled: A || n && B,
194
194
  "data-testid": "voteButton",
195
195
  to: n ? null : Q(e.id),
196
196
  target: n ? null : "_top",
@@ -201,7 +201,7 @@ const We = ({
201
201
  {
202
202
  "data-tid": "action_vote",
203
203
  className: d(o.voteButtonThesis, {
204
- [o.voteButtonThesisSynthesisMobile]: !j
204
+ [o.voteButtonThesisSynthesisMobile]: !O
205
205
  }),
206
206
  children: a
207
207
  }
@@ -212,13 +212,13 @@ const We = ({
212
212
  t
213
213
  );
214
214
  }, ge = () => {
215
- C || J.actions?.unloggedVoteResults === !0 ? f(!0) : z({ loginAction: "vote" });
215
+ x || J.actions?.unloggedVoteResults === !0 ? m(!0) : z({ loginAction: "vote" });
216
216
  };
217
217
  return /* @__PURE__ */ s(
218
218
  "div",
219
219
  {
220
- className: d(o.voteBox, { [O]: O }),
221
- children: /* @__PURE__ */ s(pe, { children: p || M ? /* @__PURE__ */ l("div", { className: o.voteResultsBox, "data-testid": "voteResultsBox", children: [
220
+ className: d(o.voteBox, { [F]: F }),
221
+ children: /* @__PURE__ */ s(pe, { children: p || A ? /* @__PURE__ */ l("div", { className: o.voteResultsBox, "data-testid": "voteResultsBox", children: [
222
222
  /* @__PURE__ */ s("div", { className: o.voteResults, children: r.map((e, t) => {
223
223
  let a;
224
224
  return t === 0 ? a = $.translatedContent : t === 1 ? a = q.translatedContent : t === 2 && (a = Y.translatedContent), /* @__PURE__ */ l("div", { children: [
@@ -235,12 +235,12 @@ const We = ({
235
235
  c && c.position_id === e.id ? /* @__PURE__ */ s(
236
236
  "span",
237
237
  {
238
- title: B.formatMessage({
238
+ title: C.formatMessage({
239
239
  id: "vote.vote_box.vote_side"
240
240
  }) + a,
241
241
  className: o.sideIcon,
242
242
  "aria-hidden": "true",
243
- children: /* @__PURE__ */ s(T, { name: "checkbox", width: 16, height: 16 })
243
+ children: /* @__PURE__ */ s(j, { name: "checkbox", width: 16, height: 16 })
244
244
  }
245
245
  ) : null
246
246
  ]
@@ -263,36 +263,36 @@ const We = ({
263
263
  }) }),
264
264
  /* @__PURE__ */ l("div", { className: o.voteBoxFooter, children: [
265
265
  te && /* @__PURE__ */ s("div", { className: o.voteResultsNumberVoters, children: /* @__PURE__ */ s(
266
- m,
266
+ f,
267
267
  {
268
268
  id: "vote.vote_box.votes",
269
269
  values: { votesCount: u },
270
270
  defaultMessage: "{votesCount} votes"
271
271
  }
272
272
  ) }),
273
- !M && /* @__PURE__ */ s("div", { children: c ? /* @__PURE__ */ s(
273
+ !A && /* @__PURE__ */ s("div", { children: c ? /* @__PURE__ */ s(
274
274
  "button",
275
275
  {
276
276
  "data-tid": "action_edit_vote",
277
277
  className: o.voteActionButton,
278
278
  type: "button",
279
- onClick: R,
279
+ onClick: L,
280
280
  children: /* @__PURE__ */ s(
281
- m,
281
+ f,
282
282
  {
283
283
  id: "vote.vote_box.update",
284
284
  defaultMessage: "Modify"
285
285
  }
286
286
  )
287
287
  }
288
- ) : !U && /* @__PURE__ */ s(
288
+ ) : !H && /* @__PURE__ */ s(
289
289
  "button",
290
290
  {
291
291
  type: "button",
292
292
  className: o.voteActionButton,
293
- onClick: () => f(!1),
293
+ onClick: () => m(!1),
294
294
  children: /* @__PURE__ */ s(
295
- m,
295
+ f,
296
296
  {
297
297
  id: "vote.vote_box.back",
298
298
  defaultMessage: "Back to vote"
@@ -306,9 +306,9 @@ const We = ({
306
306
  "div",
307
307
  {
308
308
  className: d(o.voteBoxActionsBody, {
309
- [o.voteBoxActionsBodyColumn]: j,
309
+ [o.voteBoxActionsBodyColumn]: O,
310
310
  [o.voteBoxActionsBodyOutlined]: J.layout?.outlinedVoteButtons,
311
- [F]: F
311
+ [E]: E
312
312
  }),
313
313
  children: r.map(
314
314
  (e, t) => he(e, t)
@@ -317,9 +317,9 @@ const We = ({
317
317
  ),
318
318
  oe && /* @__PURE__ */ l("div", { className: o.voteCommentCounts, children: [
319
319
  /* @__PURE__ */ l("div", { className: o.debateNumberItem, children: [
320
- /* @__PURE__ */ s(T, { name: "votebox", width: 20, height: 20 }),
320
+ /* @__PURE__ */ s(j, { name: "votebox", width: 20, height: 20 }),
321
321
  /* @__PURE__ */ s("div", { className: o.debateNumberLabel, children: /* @__PURE__ */ s(
322
- m,
322
+ f,
323
323
  {
324
324
  id: "vote.vote_box.votes",
325
325
  values: { votesCount: u },
@@ -328,9 +328,9 @@ const We = ({
328
328
  ) })
329
329
  ] }),
330
330
  /* @__PURE__ */ l("div", { className: o.debateNumberItem, children: [
331
- /* @__PURE__ */ s(T, { name: "chat", width: 20, height: 20 }),
331
+ /* @__PURE__ */ s(j, { name: "chat", width: 20, height: 20 }),
332
332
  /* @__PURE__ */ s("div", { className: o.debateNumberLabel, children: /* @__PURE__ */ s(
333
- m,
333
+ f,
334
334
  {
335
335
  id: "vote.vote_box.comments",
336
336
  values: { count: se ?? 0 },
@@ -345,9 +345,9 @@ const We = ({
345
345
  className: d(
346
346
  o.voteBoxActions,
347
347
  o.voteBoxShowResultContainer,
348
- { [I]: I }
348
+ { [U]: U }
349
349
  ),
350
- children: /* @__PURE__ */ s("div", { className: o.voteBoxShowResult, children: U ? !p && /* @__PURE__ */ s("div", { className: o.voteResultInfoText, children: B.formatMessage({
350
+ children: /* @__PURE__ */ s("div", { className: o.voteBoxShowResult, children: H ? !p && /* @__PURE__ */ s("div", { className: o.voteResultInfoText, children: C.formatMessage({
351
351
  id: "vote.vote_box.result_after_vote",
352
352
  defaultMessage: "Le résultat s'affichera après le vote."
353
353
  }) }) : typeof window < "u" && !S ? /* @__PURE__ */ s(
@@ -359,7 +359,7 @@ const We = ({
359
359
  "data-testid": "show-result",
360
360
  className: o.showResultButton,
361
361
  children: /* @__PURE__ */ s("span", { className: d(o.boldShowResult, o.outlined), children: /* @__PURE__ */ s(
362
- m,
362
+ f,
363
363
  {
364
364
  id: "vote.vote_box.show_result",
365
365
  defaultMessage: "Show result"
@@ -376,7 +376,7 @@ const We = ({
376
376
  external: !0,
377
377
  "data-testid": "show-result",
378
378
  children: /* @__PURE__ */ s("span", { className: d(o.boldShowResult, o.outlined), children: /* @__PURE__ */ s(
379
- m,
379
+ f,
380
380
  {
381
381
  id: "vote.vote_box.show_result",
382
382
  defaultMessage: "Show result"
@@ -1,44 +1,45 @@
1
- import { jsxs as d, jsx as a } from "react/jsx-runtime";
2
- import p from "classnames";
1
+ import { jsxs as b, jsx as a } from "react/jsx-runtime";
2
+ import v from "classnames";
3
3
  import "react";
4
- import { useIntl as v } from "react-intl";
4
+ import { useIntl as f } from "react-intl";
5
5
  import t from "./VoteButton.module.scss.js";
6
- import { useVote as f } from "../use_vote/useVote.js";
7
- import { Icon as b } from "../../icons/icon/Icon.js";
8
- const k = ({
9
- voteableType: r,
10
- voteableId: i,
6
+ import { useVote as g } from "../use_vote/useVote.js";
7
+ import { Icon as h } from "../../icons/icon/Icon.js";
8
+ const B = ({
9
+ voteableType: i,
10
+ voteableId: r,
11
11
  totalUpvote: n = 0,
12
12
  totalDownvote: s = 0,
13
- activeClassName: m,
14
- disabled: o = !1
13
+ activeClassName: l,
14
+ disabled: d = !1
15
15
  }) => {
16
- const { totalUpvotes: l, activeVote: e, handleVote: u } = f(
17
- r,
16
+ const { totalUpvotes: m, activeVote: e, handleVote: u, voteLoading: c } = g(
18
17
  i,
18
+ r,
19
19
  n,
20
20
  s
21
- ), c = v();
22
- return /* @__PURE__ */ d(
21
+ ), p = f(), o = d || c;
22
+ return /* @__PURE__ */ b(
23
23
  "button",
24
24
  {
25
25
  type: "button",
26
- className: p(t.voteButton, {
26
+ className: v(t.voteButton, {
27
27
  [t.active]: e,
28
- [m]: e,
28
+ [l]: e,
29
29
  [t.disabled]: o
30
30
  }),
31
31
  onClick: o ? null : () => u(!0),
32
+ disabled: o,
32
33
  "data-testid": "vote-button",
33
34
  "data-tid": "action_vote_argument",
34
35
  "aria-pressed": e,
35
- "aria-label": c.formatMessage({
36
+ "aria-label": p.formatMessage({
36
37
  id: "vote.vote_button.aria_label",
37
38
  defaultMessage: "Like argument"
38
39
  }),
39
40
  children: [
40
41
  /* @__PURE__ */ a(
41
- b,
42
+ h,
42
43
  {
43
44
  name: "clap",
44
45
  "aria-hidden": "true",
@@ -47,11 +48,11 @@ const k = ({
47
48
  width: 18
48
49
  }
49
50
  ),
50
- /* @__PURE__ */ a("span", { className: t.voteNumber, children: l })
51
+ /* @__PURE__ */ a("span", { className: t.voteNumber, children: m })
51
52
  ]
52
53
  }
53
54
  );
54
55
  };
55
56
  export {
56
- k as VoteButton
57
+ B as VoteButton
57
58
  };
@@ -1,37 +1,37 @@
1
- import { jsx as _ } from "react/jsx-runtime";
2
- import { createContext as b, useState as i, useEffect as h } from "react";
3
- import { useDataProvider as x } from "../../data/data_provider/useDataProvider.js";
4
- import { useAuth as I } from "../../auth/use_auth/useAuth.js";
5
- const P = b(), D = ({ voteableType: s, children: c }) => {
6
- const u = x(), { isLoggedIn: n, currentUser: l } = I(), [m, v] = i({}), [t, f] = i([]), p = () => {
7
- u.getList("votes", {
1
+ import { jsx as h } from "react/jsx-runtime";
2
+ import { createContext as x, useState as n, useEffect as L } from "react";
3
+ import { useDataProvider as I } from "../../data/data_provider/useDataProvider.js";
4
+ import { useAuth as P } from "../../auth/use_auth/useAuth.js";
5
+ const j = x(), E = ({ voteableType: s, children: l }) => {
6
+ const u = I(), { isLoggedIn: r, currentUser: f } = P(), [v, g] = n({}), [t, m] = n([]), [p, d] = n(!1), V = () => {
7
+ d(!0), u.getList("votes", {
8
8
  page: 1,
9
9
  per_page: Math.max(1, t.length),
10
- user_id: l.id,
10
+ user_id: f.id,
11
11
  voteable_id: t.join(","),
12
12
  voteable_type: s,
13
13
  countless: !0
14
14
  }).then((e) => {
15
15
  if (e.data.success) {
16
- const a = e.data.data, r = {};
16
+ const a = e.data.data, i = {};
17
17
  t.map((o) => {
18
- const V = a.find(
19
- (d) => d.voteable_id === o && d.voteable_type === s
18
+ const b = a.find(
19
+ (c) => c.voteable_id === o && c.voteable_type === s
20
20
  );
21
- r[o] = V || null;
22
- }), v((o) => ({ ...o, ...r }));
21
+ i[o] = b || null;
22
+ }), g((o) => ({ ...o, ...i }));
23
23
  }
24
- });
24
+ }).finally(() => d(!1));
25
25
  };
26
- h(() => {
27
- n && s && t && t.length > 0 && p();
28
- }, [n, t]);
29
- const g = (e) => {
30
- f((a) => [...a, ...e]);
26
+ L(() => {
27
+ r && s && t && t.length > 0 && V();
28
+ }, [r, t]);
29
+ const _ = (e) => {
30
+ m((a) => [...a, ...e]);
31
31
  };
32
- return /* @__PURE__ */ _(P.Provider, { value: { votes: m, addVoteableIds: g }, children: c });
32
+ return /* @__PURE__ */ h(j.Provider, { value: { votes: v, voteableIds: t, votesLoading: p, addVoteableIds: _ }, children: l });
33
33
  };
34
34
  export {
35
- P as VoteContext,
36
- D as VoteProvider
35
+ j as VoteContext,
36
+ E as VoteProvider
37
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logora/debate",
3
- "version": "0.4.59",
3
+ "version": "0.4.61",
4
4
  "type": "module",
5
5
  "license": "AGPL-3.0",
6
6
  "description": "Design system of @Logora made with React",