@logora/debate 0.4.60 → 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.
- package/dist/components/auth/use_auth/authTokenHandler.js +27 -22
- package/dist/components/vote/suggestion_vote_box/SuggestionVoteBox.js +31 -31
- package/dist/components/vote/up_down_vote_box/UpDownVoteBox.js +25 -25
- package/dist/components/vote/use_vote/useVote.js +37 -36
- package/dist/components/vote/vote_box/VoteBox.js +70 -70
- package/dist/components/vote/vote_button/VoteButton.js +21 -20
- package/dist/components/vote/vote_provider/VoteProvider.js +22 -22
- package/package.json +1 -1
|
@@ -1,41 +1,46 @@
|
|
|
1
|
-
import { makeStorage as
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
},
|
|
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:
|
|
9
|
+
session_id: r
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
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
|
|
17
|
-
|
|
18
|
+
const T = n.data;
|
|
19
|
+
f(T, r), c(n);
|
|
18
20
|
} else
|
|
19
|
-
|
|
21
|
+
u(n);
|
|
20
22
|
}).catch((n) => {
|
|
21
|
-
|
|
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:
|
|
31
|
+
getToken: l,
|
|
27
32
|
removeToken: d,
|
|
28
|
-
fetchToken:
|
|
33
|
+
fetchToken: h,
|
|
29
34
|
refreshToken: () => {
|
|
30
35
|
if (o) return o;
|
|
31
|
-
const e =
|
|
36
|
+
const e = l(), r = {
|
|
32
37
|
grant_type: "refresh_token",
|
|
33
38
|
refresh_token: e.refresh_token
|
|
34
39
|
};
|
|
35
|
-
return o =
|
|
40
|
+
return o = i.post(k, r).then((t) => {
|
|
36
41
|
if (t.data.access_token) {
|
|
37
|
-
const
|
|
38
|
-
return
|
|
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
|
-
|
|
53
|
+
y as authTokenHandler
|
|
49
54
|
};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { Suspense as
|
|
3
|
-
import { useIntl as
|
|
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
|
|
6
|
-
import { useVote as
|
|
7
|
-
import { useModal as
|
|
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
|
|
10
|
-
import { ConfirmModal as
|
|
11
|
-
const
|
|
12
|
-
voteableType:
|
|
13
|
-
voteableId:
|
|
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:
|
|
16
|
-
onVote:
|
|
17
|
-
disabled:
|
|
15
|
+
totalDownvote: c = 0,
|
|
16
|
+
onVote: f,
|
|
17
|
+
disabled: g = !1
|
|
18
18
|
}) => {
|
|
19
|
-
const t =
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
), { showModal:
|
|
26
|
-
|
|
27
|
-
/* @__PURE__ */ e(
|
|
28
|
-
|
|
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: () =>
|
|
46
|
+
onConfirmCallback: () => n(!1)
|
|
47
47
|
}
|
|
48
48
|
) })
|
|
49
49
|
));
|
|
50
50
|
};
|
|
51
|
-
return /* @__PURE__ */
|
|
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 : () =>
|
|
56
|
+
onClick: o ? null : () => n(!0),
|
|
57
57
|
"data-testid": "upvote-button",
|
|
58
58
|
disabled: o,
|
|
59
59
|
rightIcon: /* @__PURE__ */ e(
|
|
60
|
-
|
|
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 &&
|
|
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 : () =>
|
|
80
|
+
onClick: o ? null : () => b(),
|
|
81
81
|
disabled: o,
|
|
82
|
-
rightIcon: /* @__PURE__ */ e(
|
|
83
|
-
active: !(s && !
|
|
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
|
-
|
|
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
|
|
2
|
+
import d from "classnames";
|
|
3
3
|
import "react";
|
|
4
|
-
import { useIntl as
|
|
4
|
+
import { useIntl as x } from "react-intl";
|
|
5
5
|
import e from "./UpDownVoteBox.module.scss.js";
|
|
6
|
-
import { useVote as
|
|
7
|
-
import { Icon as
|
|
8
|
-
const
|
|
9
|
-
voteableType:
|
|
10
|
-
voteableId:
|
|
11
|
-
totalUpvote:
|
|
12
|
-
totalDownvote:
|
|
13
|
-
disabled:
|
|
14
|
-
hideDownvotes:
|
|
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:
|
|
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:
|
|
21
|
+
className: d(e.upvoteContainer, {
|
|
22
22
|
[e.disabled]: t,
|
|
23
|
-
[e.active]: s &&
|
|
23
|
+
[e.active]: s && i
|
|
24
24
|
}),
|
|
25
|
-
onClick: t ? null : () =>
|
|
25
|
+
onClick: t ? null : () => n(!0),
|
|
26
26
|
"data-testid": "upvote-button",
|
|
27
27
|
children: [
|
|
28
28
|
/* @__PURE__ */ o(
|
|
29
|
-
|
|
29
|
+
r,
|
|
30
30
|
{
|
|
31
31
|
name: "upvote",
|
|
32
32
|
width: 27,
|
|
33
33
|
height: 25,
|
|
34
|
-
"aria-label":
|
|
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:
|
|
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:
|
|
47
|
+
className: d(e.downvoteContainer, {
|
|
48
48
|
[e.disabled]: t,
|
|
49
|
-
[e.active]: s && !
|
|
49
|
+
[e.active]: s && !i
|
|
50
50
|
}),
|
|
51
|
-
onClick: t ? null : () =>
|
|
51
|
+
onClick: t ? null : () => n(!1),
|
|
52
52
|
"data-testid": "downvote-button",
|
|
53
53
|
children: [
|
|
54
54
|
/* @__PURE__ */ o(
|
|
55
|
-
|
|
55
|
+
r,
|
|
56
56
|
{
|
|
57
57
|
name: "downvote",
|
|
58
58
|
width: 27,
|
|
59
59
|
height: 25,
|
|
60
|
-
"aria-label":
|
|
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
|
-
!
|
|
66
|
+
!f && /* @__PURE__ */ o("div", { className: e.voteText, children: b })
|
|
67
67
|
]
|
|
68
68
|
}
|
|
69
69
|
)
|
|
70
70
|
] });
|
|
71
71
|
};
|
|
72
72
|
export {
|
|
73
|
-
|
|
73
|
+
k as UpDownVoteBox
|
|
74
74
|
};
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { useContext as
|
|
2
|
-
import { VoteContext as
|
|
3
|
-
import { useAuth as
|
|
4
|
-
import { useDataProvider as
|
|
5
|
-
import { useAuthRequired as
|
|
6
|
-
const
|
|
7
|
-
const { votes: f } =
|
|
8
|
-
|
|
9
|
-
if (!
|
|
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
|
-
|
|
11
|
+
k(!0), h(!!e), g(e?.is_upvote), m(e?.id);
|
|
12
12
|
}
|
|
13
13
|
}, [f, i]);
|
|
14
|
-
const
|
|
15
|
-
h(!0),
|
|
16
|
-
const t = e ?
|
|
17
|
-
|
|
18
|
-
},
|
|
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 ?
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
if (
|
|
24
|
-
if (
|
|
25
|
-
|
|
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) :
|
|
27
|
+
t.data?.success ? m(null) : r(e), s(!1);
|
|
28
28
|
},
|
|
29
29
|
(t) => {
|
|
30
|
-
|
|
30
|
+
r(e), s(!1);
|
|
31
31
|
}
|
|
32
32
|
);
|
|
33
33
|
else {
|
|
34
|
-
|
|
34
|
+
c(!e), r(e);
|
|
35
35
|
const t = {
|
|
36
36
|
is_upvote: e
|
|
37
37
|
};
|
|
38
|
-
s(!0), V.update("votes",
|
|
38
|
+
s(!0), V.update("votes", b, t).then(
|
|
39
39
|
(o) => {
|
|
40
|
-
o.data?.success || (
|
|
40
|
+
o.data?.success || (c(e), r(!e)), s(!1);
|
|
41
41
|
},
|
|
42
42
|
(o) => {
|
|
43
|
-
|
|
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
|
-
|
|
53
|
+
r(e), s(!0), V.create("votes", t).then(
|
|
54
54
|
(o) => {
|
|
55
|
-
o.data?.success ? m(o.data.data.resource.id) :
|
|
55
|
+
o.data?.success ? m(o.data.data.resource.id) : c(e), s(!1);
|
|
56
56
|
},
|
|
57
57
|
(o) => {
|
|
58
|
-
|
|
58
|
+
c(e), s(!1);
|
|
59
59
|
}
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
return {
|
|
64
|
-
totalUpvotes:
|
|
64
|
+
totalUpvotes: l,
|
|
65
65
|
totalDownvotes: u,
|
|
66
|
-
activeVote:
|
|
67
|
-
voteSide:
|
|
66
|
+
activeVote: T,
|
|
67
|
+
voteSide: D,
|
|
68
68
|
handleVote: (e) => {
|
|
69
|
-
|
|
70
|
-
}
|
|
69
|
+
!C && !A && (i ? E(e) : B({ loginAction: "vote" }));
|
|
70
|
+
},
|
|
71
|
+
voteLoading: A
|
|
71
72
|
};
|
|
72
73
|
};
|
|
73
74
|
export {
|
|
74
|
-
|
|
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
|
|
5
|
-
import { useIntl as _e, FormattedMessage as
|
|
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
|
|
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
|
|
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:
|
|
24
|
+
displayColumn: O,
|
|
25
25
|
textAlignLeft: ee,
|
|
26
26
|
showTotal: te = !0,
|
|
27
|
-
voteBoxClassName:
|
|
28
|
-
buttonContainerClassName:
|
|
29
|
-
buttonClassName:
|
|
30
|
-
showResultClassName:
|
|
27
|
+
voteBoxClassName: F,
|
|
28
|
+
buttonContainerClassName: E,
|
|
29
|
+
buttonClassName: I,
|
|
30
|
+
showResultClassName: U,
|
|
31
31
|
onVote: w,
|
|
32
|
-
disabled:
|
|
32
|
+
disabled: A = !1,
|
|
33
33
|
showVotesCommentsNumber: oe = !1,
|
|
34
34
|
commentsCount: se,
|
|
35
|
-
hideShowResultButton:
|
|
35
|
+
hideShowResultButton: H = !1
|
|
36
36
|
}) => {
|
|
37
|
-
const [
|
|
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
|
-
), $ =
|
|
42
|
+
), $ = T(
|
|
43
43
|
r[0]?.name,
|
|
44
44
|
r[0]?.language,
|
|
45
45
|
"name",
|
|
46
46
|
r[0]?.translation_entries
|
|
47
|
-
), q =
|
|
47
|
+
), q = T(
|
|
48
48
|
r[1]?.name,
|
|
49
49
|
r[1]?.language,
|
|
50
50
|
"name",
|
|
51
51
|
r[1]?.translation_entries
|
|
52
|
-
), Y =
|
|
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(),
|
|
71
|
-
|
|
72
|
-
K === !1 && (
|
|
73
|
-
}, [K,
|
|
74
|
-
if (
|
|
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) :
|
|
76
|
+
e && (t ? X(t) : m(!0));
|
|
77
77
|
}
|
|
78
|
-
}, [
|
|
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),
|
|
90
|
-
t.data.data.resource ? (
|
|
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
|
-
},
|
|
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 &&
|
|
105
|
-
n.data.success && (
|
|
106
|
-
|
|
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
|
-
})) : (
|
|
113
|
-
n.data.success && (
|
|
114
|
-
|
|
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
|
-
},
|
|
121
|
+
}, me = (e) => {
|
|
122
122
|
const t = i[e].count + 1, a = u + 1, n = {};
|
|
123
|
-
r.forEach((
|
|
124
|
-
if (e ===
|
|
125
|
-
n[
|
|
123
|
+
r.forEach((M) => {
|
|
124
|
+
if (e === M.id)
|
|
125
|
+
n[M.id] = {
|
|
126
126
|
count: t,
|
|
127
|
-
percentage:
|
|
127
|
+
percentage: V(t, a)
|
|
128
128
|
};
|
|
129
129
|
else {
|
|
130
|
-
const Z = i[
|
|
131
|
-
n[
|
|
130
|
+
const Z = i[M.id].count;
|
|
131
|
+
n[M.id] = {
|
|
132
132
|
count: Z,
|
|
133
|
-
percentage:
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
-
},
|
|
171
|
-
p && ie(),
|
|
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
|
-
[
|
|
190
|
+
[I]: I
|
|
191
191
|
}),
|
|
192
192
|
onClick: n ? () => X(e.id) : null,
|
|
193
|
-
disabled:
|
|
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]: !
|
|
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
|
-
|
|
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, { [
|
|
221
|
-
children: /* @__PURE__ */ s(pe, { children: p ||
|
|
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:
|
|
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(
|
|
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
|
-
|
|
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
|
-
!
|
|
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:
|
|
279
|
+
onClick: L,
|
|
280
280
|
children: /* @__PURE__ */ s(
|
|
281
|
-
|
|
281
|
+
f,
|
|
282
282
|
{
|
|
283
283
|
id: "vote.vote_box.update",
|
|
284
284
|
defaultMessage: "Modify"
|
|
285
285
|
}
|
|
286
286
|
)
|
|
287
287
|
}
|
|
288
|
-
) : !
|
|
288
|
+
) : !H && /* @__PURE__ */ s(
|
|
289
289
|
"button",
|
|
290
290
|
{
|
|
291
291
|
type: "button",
|
|
292
292
|
className: o.voteActionButton,
|
|
293
|
-
onClick: () =>
|
|
293
|
+
onClick: () => m(!1),
|
|
294
294
|
children: /* @__PURE__ */ s(
|
|
295
|
-
|
|
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]:
|
|
309
|
+
[o.voteBoxActionsBodyColumn]: O,
|
|
310
310
|
[o.voteBoxActionsBodyOutlined]: J.layout?.outlinedVoteButtons,
|
|
311
|
-
[
|
|
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(
|
|
320
|
+
/* @__PURE__ */ s(j, { name: "votebox", width: 20, height: 20 }),
|
|
321
321
|
/* @__PURE__ */ s("div", { className: o.debateNumberLabel, children: /* @__PURE__ */ s(
|
|
322
|
-
|
|
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(
|
|
331
|
+
/* @__PURE__ */ s(j, { name: "chat", width: 20, height: 20 }),
|
|
332
332
|
/* @__PURE__ */ s("div", { className: o.debateNumberLabel, children: /* @__PURE__ */ s(
|
|
333
|
-
|
|
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
|
-
{ [
|
|
348
|
+
{ [U]: U }
|
|
349
349
|
),
|
|
350
|
-
children: /* @__PURE__ */ s("div", { className: o.voteBoxShowResult, children:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
2
|
-
import
|
|
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
|
|
4
|
+
import { useIntl as f } from "react-intl";
|
|
5
5
|
import t from "./VoteButton.module.scss.js";
|
|
6
|
-
import { useVote as
|
|
7
|
-
import { Icon as
|
|
8
|
-
const
|
|
9
|
-
voteableType:
|
|
10
|
-
voteableId:
|
|
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:
|
|
14
|
-
disabled:
|
|
13
|
+
activeClassName: l,
|
|
14
|
+
disabled: d = !1
|
|
15
15
|
}) => {
|
|
16
|
-
const { totalUpvotes:
|
|
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
|
-
),
|
|
22
|
-
return /* @__PURE__ */
|
|
21
|
+
), p = f(), o = d || c;
|
|
22
|
+
return /* @__PURE__ */ b(
|
|
23
23
|
"button",
|
|
24
24
|
{
|
|
25
25
|
type: "button",
|
|
26
|
-
className:
|
|
26
|
+
className: v(t.voteButton, {
|
|
27
27
|
[t.active]: e,
|
|
28
|
-
[
|
|
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":
|
|
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
|
-
|
|
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:
|
|
51
|
+
/* @__PURE__ */ a("span", { className: t.voteNumber, children: m })
|
|
51
52
|
]
|
|
52
53
|
}
|
|
53
54
|
);
|
|
54
55
|
};
|
|
55
56
|
export {
|
|
56
|
-
|
|
57
|
+
B as VoteButton
|
|
57
58
|
};
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { useDataProvider as
|
|
4
|
-
import { useAuth as
|
|
5
|
-
const
|
|
6
|
-
const u =
|
|
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:
|
|
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,
|
|
16
|
+
const a = e.data.data, i = {};
|
|
17
17
|
t.map((o) => {
|
|
18
|
-
const
|
|
19
|
-
(
|
|
18
|
+
const b = a.find(
|
|
19
|
+
(c) => c.voteable_id === o && c.voteable_type === s
|
|
20
20
|
);
|
|
21
|
-
|
|
22
|
-
}),
|
|
21
|
+
i[o] = b || null;
|
|
22
|
+
}), g((o) => ({ ...o, ...i }));
|
|
23
23
|
}
|
|
24
|
-
});
|
|
24
|
+
}).finally(() => d(!1));
|
|
25
25
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}, [
|
|
29
|
-
const
|
|
30
|
-
|
|
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__ */
|
|
32
|
+
return /* @__PURE__ */ h(j.Provider, { value: { votes: v, voteableIds: t, votesLoading: p, addVoteableIds: _ }, children: l });
|
|
33
33
|
};
|
|
34
34
|
export {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
j as VoteContext,
|
|
36
|
+
E as VoteProvider
|
|
37
37
|
};
|