@logora/debate 0.4.92 → 0.4.94
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/auth_initializer/AuthInitializer.js +1 -1
- package/dist/components/auth/auth_modal/AuthModal.js +1 -1
- package/dist/components/auth/use_auth/authTokenHandler.js +47 -34
- package/dist/components/auth/use_auth/useAuthInterceptor.js +12 -32
- package/dist/components/data/http_client/httpClient.js +103 -0
- package/dist/components/vote/vote_box/VoteBox.js +193 -190
- package/dist/index.js +1 -1
- package/package.json +1 -2
- package/dist/components/data/axios_client/httpClient.js +0 -8
|
@@ -9,7 +9,7 @@ import { useAuthRequired as D } from "../../hooks/use_auth_required/useAuthRequi
|
|
|
9
9
|
import { AuthProviderFactory as F } from "../providers/AuthProviderFactory.js";
|
|
10
10
|
import { OnboardingModal as J } from "../../user/onboarding_modal/OnboardingModal.js";
|
|
11
11
|
import { saveOnboardingBeforeLogin as M } from "../../user/onboarding_modal/useOnboarding.js";
|
|
12
|
-
import { httpClient as d } from "../../data/
|
|
12
|
+
import { httpClient as d } from "../../data/http_client/httpClient.js";
|
|
13
13
|
const j = (e) => {
|
|
14
14
|
const t = e.replace(/-/g, "+").replace(/_/g, "/"), a = t.padEnd(t.length + (4 - t.length % 4) % 4, "=");
|
|
15
15
|
return new TextDecoder().decode(Uint8Array.from(atob(a), (r) => r.charCodeAt(0)));
|
|
@@ -5,7 +5,7 @@ import { useConfig as I } from "../../data/config_provider/useConfig.js";
|
|
|
5
5
|
import { useModal as y } from "../../dialog/modal/useModal.js";
|
|
6
6
|
import { useAuth as C } from "../use_auth/useAuth.js";
|
|
7
7
|
import { useAuthActions as E } from "../use_auth/useAuthActions.js";
|
|
8
|
-
import { httpClient as P } from "../../data/
|
|
8
|
+
import { httpClient as P } from "../../data/http_client/httpClient.js";
|
|
9
9
|
import { Modal as T } from "../../dialog/modal/Modal.js";
|
|
10
10
|
import { Loader as R } from "../../progress/loader/Loader.js";
|
|
11
11
|
import { SocialAuthForm as B } from "../social_auth_form/SocialAuthForm.js";
|
|
@@ -1,54 +1,67 @@
|
|
|
1
|
-
import { makeStorage as
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
},
|
|
1
|
+
import { makeStorage as y } from "./AuthStorage.js";
|
|
2
|
+
const p = (k, c, _) => {
|
|
3
|
+
const i = y(_), u = () => i.getToken(), f = () => {
|
|
4
|
+
i.removeToken();
|
|
5
|
+
}, l = (e, n) => {
|
|
6
6
|
const t = {
|
|
7
7
|
...e,
|
|
8
8
|
expires_at: e.created_at + e.expires_in,
|
|
9
|
-
session_id:
|
|
9
|
+
session_id: n
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
i.setToken(t);
|
|
12
12
|
};
|
|
13
13
|
let s = null;
|
|
14
|
-
const
|
|
14
|
+
const T = (e) => {
|
|
15
15
|
if (s) return s;
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
const
|
|
19
|
-
|
|
16
|
+
const n = e.session_id, t = new Promise((a, h) => k.post(c, e).then((r) => {
|
|
17
|
+
if (r.data.access_token) {
|
|
18
|
+
const x = r.data;
|
|
19
|
+
l(x, n), a(r);
|
|
20
20
|
} else
|
|
21
|
-
|
|
22
|
-
}).catch((
|
|
23
|
-
|
|
21
|
+
h(r);
|
|
22
|
+
}).catch((r) => {
|
|
23
|
+
h(r);
|
|
24
24
|
})).finally(() => {
|
|
25
25
|
s = null;
|
|
26
26
|
});
|
|
27
27
|
return s = t, t;
|
|
28
28
|
};
|
|
29
29
|
let o = null;
|
|
30
|
+
const d = () => {
|
|
31
|
+
if (o) return o;
|
|
32
|
+
const e = u(), n = {
|
|
33
|
+
grant_type: "refresh_token",
|
|
34
|
+
refresh_token: e.refresh_token
|
|
35
|
+
};
|
|
36
|
+
return o = k.post(c, n).then((t) => {
|
|
37
|
+
if (t.data.access_token) {
|
|
38
|
+
const a = t.data;
|
|
39
|
+
return l(a, e.session_id), a.access_token;
|
|
40
|
+
}
|
|
41
|
+
return Promise.reject(t);
|
|
42
|
+
}).finally(() => {
|
|
43
|
+
o = null;
|
|
44
|
+
}), o;
|
|
45
|
+
}, m = (e) => {
|
|
46
|
+
try {
|
|
47
|
+
return e.expires_at < Date.now() / 1e3;
|
|
48
|
+
} catch {
|
|
49
|
+
return !1;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
30
52
|
return {
|
|
31
|
-
getToken:
|
|
32
|
-
removeToken:
|
|
33
|
-
fetchToken:
|
|
34
|
-
refreshToken:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
return o = i.post(k, r).then((t) => {
|
|
41
|
-
if (t.data.access_token) {
|
|
42
|
-
const c = t.data;
|
|
43
|
-
return f(c, e.session_id), c.access_token;
|
|
44
|
-
}
|
|
45
|
-
return Promise.reject(t);
|
|
46
|
-
}).finally(() => {
|
|
47
|
-
o = null;
|
|
48
|
-
}), o;
|
|
53
|
+
getToken: u,
|
|
54
|
+
removeToken: f,
|
|
55
|
+
fetchToken: T,
|
|
56
|
+
refreshToken: d,
|
|
57
|
+
ensureValidToken: (e) => {
|
|
58
|
+
if (!e?.headers?.authorization)
|
|
59
|
+
return e;
|
|
60
|
+
const n = u();
|
|
61
|
+
return !n || !m(n) || e.url === c ? e : d().then((t) => (e.headers.authorization = `Bearer ${t}`, e));
|
|
49
62
|
}
|
|
50
63
|
};
|
|
51
64
|
};
|
|
52
65
|
export {
|
|
53
|
-
|
|
66
|
+
p as authTokenHandler
|
|
54
67
|
};
|
|
@@ -1,35 +1,15 @@
|
|
|
1
|
-
import { useEffect as
|
|
2
|
-
import { authTokenHandler as
|
|
3
|
-
const
|
|
4
|
-
const {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
),
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} catch {
|
|
12
|
-
return !1;
|
|
13
|
-
}
|
|
1
|
+
import { useEffect as s } from "react";
|
|
2
|
+
import { authTokenHandler as u } from "./authTokenHandler.js";
|
|
3
|
+
const f = (e, r, t) => (s(() => {
|
|
4
|
+
const { ensureValidToken: o } = u(
|
|
5
|
+
e,
|
|
6
|
+
r,
|
|
7
|
+
t
|
|
8
|
+
), n = e.interceptors.request.use(o);
|
|
9
|
+
return () => {
|
|
10
|
+
e.interceptors.request.eject?.(n);
|
|
14
11
|
};
|
|
15
|
-
|
|
16
|
-
t.interceptors.request.use(
|
|
17
|
-
(e) => {
|
|
18
|
-
const r = e;
|
|
19
|
-
if (r.headers.authorization) {
|
|
20
|
-
const n = u();
|
|
21
|
-
if (n && i(n) && e.url !== o)
|
|
22
|
-
return a().then((c) => {
|
|
23
|
-
const h = `Bearer ${c}`;
|
|
24
|
-
return r.headers.authorization = h, Promise.resolve(r);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return e;
|
|
28
|
-
},
|
|
29
|
-
(e) => Promise.reject(e)
|
|
30
|
-
);
|
|
31
|
-
}, []), null;
|
|
32
|
-
};
|
|
12
|
+
}, []), null);
|
|
33
13
|
export {
|
|
34
|
-
|
|
14
|
+
f as useAuthInterceptor
|
|
35
15
|
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const C = "application/json", g = "application/json, text/plain, */*", f = [], E = (t) => t instanceof Date ? t.toISOString() : String(t), A = (t, e) => {
|
|
2
|
+
if (!e)
|
|
3
|
+
return t;
|
|
4
|
+
const n = new URLSearchParams();
|
|
5
|
+
for (const [c, i] of Object.entries(e))
|
|
6
|
+
if (i != null)
|
|
7
|
+
if (Array.isArray(i))
|
|
8
|
+
for (const o of i)
|
|
9
|
+
o != null && n.append(`${c}[]`, E(o));
|
|
10
|
+
else
|
|
11
|
+
n.append(c, E(i));
|
|
12
|
+
const r = n.toString();
|
|
13
|
+
return r ? t.includes("?") ? `${t}&${r}` : `${t}?${r}` : t;
|
|
14
|
+
}, O = (t) => t ? Array.isArray(t) ? Object.fromEntries(t) : typeof t.entries == "function" ? Object.fromEntries(t.entries()) : { ...t } : {}, w = (t, e) => {
|
|
15
|
+
const n = e.toLowerCase();
|
|
16
|
+
return Object.keys(t).some((r) => r.toLowerCase() === n);
|
|
17
|
+
}, P = (t) => {
|
|
18
|
+
const e = {};
|
|
19
|
+
if (!t)
|
|
20
|
+
return e;
|
|
21
|
+
for (const [n, r] of t.entries())
|
|
22
|
+
e[n.toLowerCase()] = r;
|
|
23
|
+
return e;
|
|
24
|
+
}, H = (t, e) => {
|
|
25
|
+
if (t != null)
|
|
26
|
+
return typeof FormData < "u" && t instanceof FormData || typeof t == "string" ? t : (w(e, "content-type") || (e["Content-Type"] = C), JSON.stringify(t));
|
|
27
|
+
}, S = (t) => {
|
|
28
|
+
if (!t)
|
|
29
|
+
return "";
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(t);
|
|
32
|
+
} catch {
|
|
33
|
+
return t;
|
|
34
|
+
}
|
|
35
|
+
}, h = (t, e, n) => {
|
|
36
|
+
const r = new Error(t);
|
|
37
|
+
return e && (r.response = e), n && (r.code = n), r;
|
|
38
|
+
}, b = async (t) => {
|
|
39
|
+
let e = t;
|
|
40
|
+
for (const n of [...f])
|
|
41
|
+
e = await n(e);
|
|
42
|
+
return e;
|
|
43
|
+
}, u = async (t, e, n, r) => {
|
|
44
|
+
const { params: c, headers: i = {}, timeout: o = 1e4 } = r ?? {}, d = O(i);
|
|
45
|
+
w(d, "accept") || (d.Accept = g);
|
|
46
|
+
const a = await b({
|
|
47
|
+
url: A(e, c),
|
|
48
|
+
method: t,
|
|
49
|
+
headers: d,
|
|
50
|
+
data: n,
|
|
51
|
+
timeout: o
|
|
52
|
+
}), p = O(a.headers), l = new AbortController();
|
|
53
|
+
let y = !1;
|
|
54
|
+
const T = o ? setTimeout(() => {
|
|
55
|
+
y = !0, l.abort();
|
|
56
|
+
}, o) : null;
|
|
57
|
+
try {
|
|
58
|
+
const s = await fetch(a.url, {
|
|
59
|
+
method: a.method,
|
|
60
|
+
headers: p,
|
|
61
|
+
body: H(a.data, p),
|
|
62
|
+
signal: l.signal
|
|
63
|
+
}), m = {
|
|
64
|
+
data: S(await s.text()),
|
|
65
|
+
status: s.status,
|
|
66
|
+
statusText: s.statusText,
|
|
67
|
+
headers: P(s.headers)
|
|
68
|
+
};
|
|
69
|
+
if (!s.ok)
|
|
70
|
+
throw h(
|
|
71
|
+
`Request failed with status code ${s.status}`,
|
|
72
|
+
m
|
|
73
|
+
);
|
|
74
|
+
return m;
|
|
75
|
+
} catch (s) {
|
|
76
|
+
throw y ? h(
|
|
77
|
+
`timeout of ${o}ms exceeded`,
|
|
78
|
+
void 0,
|
|
79
|
+
"ECONNABORTED"
|
|
80
|
+
) : s;
|
|
81
|
+
} finally {
|
|
82
|
+
T && clearTimeout(T);
|
|
83
|
+
}
|
|
84
|
+
}, q = {
|
|
85
|
+
interceptors: {
|
|
86
|
+
request: {
|
|
87
|
+
use: (t) => (f.push(t), () => {
|
|
88
|
+
const e = f.indexOf(t);
|
|
89
|
+
e !== -1 && f.splice(e, 1);
|
|
90
|
+
}),
|
|
91
|
+
eject: (t) => {
|
|
92
|
+
typeof t == "function" && t();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
get: (t, e) => u("GET", t, void 0, e),
|
|
97
|
+
delete: (t, e) => u("DELETE", t, void 0, e),
|
|
98
|
+
post: (t, e, n) => u("POST", t, e, n),
|
|
99
|
+
patch: (t, e, n) => u("PATCH", t, e, n)
|
|
100
|
+
};
|
|
101
|
+
export {
|
|
102
|
+
q as httpClient
|
|
103
|
+
};
|
|
@@ -1,207 +1,210 @@
|
|
|
1
|
-
import { jsx as s, Fragment as
|
|
2
|
-
import
|
|
3
|
-
import { useState as
|
|
4
|
-
import { useIntl as
|
|
5
|
-
import { useLocation as
|
|
1
|
+
import { jsx as s, Fragment as be, jsxs as d } from "react/jsx-runtime";
|
|
2
|
+
import u from "classnames";
|
|
3
|
+
import { useState as S, useEffect as y } from "react";
|
|
4
|
+
import { useIntl as Se, FormattedMessage as m } from "react-intl";
|
|
5
|
+
import { useLocation as we } from "react-router";
|
|
6
6
|
import o from "./VoteBox.module.scss.js";
|
|
7
|
-
import { useTranslatedContent as
|
|
8
|
-
import { useSessionStorageState as
|
|
9
|
-
import { useToast as
|
|
10
|
-
import { useAuthRequired as
|
|
11
|
-
import { useDataProvider as
|
|
12
|
-
import { useConfig as
|
|
13
|
-
import { useAuth as
|
|
14
|
-
import { Icon as
|
|
15
|
-
import { ProgressBar as
|
|
16
|
-
import { Link as
|
|
17
|
-
import { Button as
|
|
18
|
-
const
|
|
19
|
-
numberVotes:
|
|
20
|
-
votePositions:
|
|
21
|
-
voteableType:
|
|
22
|
-
voteableId:
|
|
23
|
-
redirectUrl:
|
|
24
|
-
displayColumn:
|
|
25
|
-
textAlignLeft:
|
|
26
|
-
showTotal:
|
|
27
|
-
voteBoxClassName:
|
|
28
|
-
buttonContainerClassName:
|
|
29
|
-
buttonClassName:
|
|
30
|
-
showResultClassName:
|
|
31
|
-
onVote:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
7
|
+
import { useTranslatedContent as O } from "../../translation/translated_content/useTranslatedContent.js";
|
|
8
|
+
import { useSessionStorageState as te } from "../../hooks/use_session_storage_state/useSessionStorageState.js";
|
|
9
|
+
import { useToast as Be } from "../../dialog/toast_provider/useToast.js";
|
|
10
|
+
import { useAuthRequired as Ve } from "../../hooks/use_auth_required/useAuthRequired.js";
|
|
11
|
+
import { useDataProvider as Ce } from "../../data/data_provider/useDataProvider.js";
|
|
12
|
+
import { useConfig as xe } from "../../data/config_provider/useConfig.js";
|
|
13
|
+
import { useAuth as Ae } from "../../auth/use_auth/useAuth.js";
|
|
14
|
+
import { Icon as E } from "../../icons/icon/Icon.js";
|
|
15
|
+
import { ProgressBar as ye } from "../../progress/progress_bar/ProgressBar.js";
|
|
16
|
+
import { Link as Me } from "../../action/link/Link.js";
|
|
17
|
+
import { Button as Re } from "../../action/button/Button.js";
|
|
18
|
+
const Ke = ({
|
|
19
|
+
numberVotes: w,
|
|
20
|
+
votePositions: i,
|
|
21
|
+
voteableType: h,
|
|
22
|
+
voteableId: g,
|
|
23
|
+
redirectUrl: B,
|
|
24
|
+
displayColumn: I,
|
|
25
|
+
textAlignLeft: oe,
|
|
26
|
+
showTotal: se = !0,
|
|
27
|
+
voteBoxClassName: U,
|
|
28
|
+
buttonContainerClassName: H,
|
|
29
|
+
buttonClassName: $,
|
|
30
|
+
showResultClassName: q,
|
|
31
|
+
onVote: V,
|
|
32
|
+
onVoteCountsChange: ae,
|
|
33
|
+
disabled: M = !1,
|
|
34
|
+
showVotesCommentsNumber: ne = !1,
|
|
35
|
+
commentsCount: re,
|
|
36
|
+
hideShowResultButton: D = !1
|
|
36
37
|
}) => {
|
|
37
|
-
const [
|
|
38
|
-
Number.parseFloat(
|
|
38
|
+
const [C, p] = S(!0), [l, R] = S(void 0), [N, v] = S(!1), [c, G] = S(
|
|
39
|
+
Number.parseFloat(w.total) || Object.values(w).reduce(
|
|
39
40
|
(e, t) => e + Number.parseFloat(t),
|
|
40
41
|
0
|
|
41
42
|
) || 0
|
|
42
|
-
),
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
), W = O(
|
|
44
|
+
i[0]?.name,
|
|
45
|
+
i[0]?.language,
|
|
45
46
|
"name",
|
|
46
|
-
|
|
47
|
-
), Y =
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
i[0]?.translation_entries
|
|
48
|
+
), Y = O(
|
|
49
|
+
i[1]?.name,
|
|
50
|
+
i[1]?.language,
|
|
50
51
|
"name",
|
|
51
|
-
|
|
52
|
-
),
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
i[1]?.translation_entries
|
|
53
|
+
), z = O(
|
|
54
|
+
i[2]?.name,
|
|
55
|
+
i[2]?.language,
|
|
55
56
|
"name",
|
|
56
|
-
|
|
57
|
-
), [_,
|
|
57
|
+
i[2]?.translation_entries
|
|
58
|
+
), [_, ie, J] = te(
|
|
58
59
|
"storedUserVote",
|
|
59
60
|
{}
|
|
60
|
-
), [
|
|
61
|
+
), [Le, le, ce] = te("userSide", {}), { toast: de } = Be() || {}, ue = () => {
|
|
61
62
|
const e = {};
|
|
62
|
-
return
|
|
63
|
+
return i?.forEach(
|
|
63
64
|
(t) => e[t.id] = {
|
|
64
|
-
count: Number.parseFloat(
|
|
65
|
-
percentage:
|
|
66
|
-
100 * ((
|
|
65
|
+
count: Number.parseFloat(w[t.id]) || 0,
|
|
66
|
+
percentage: c === 0 ? 0 : Math.round(
|
|
67
|
+
100 * ((w[t.id] || 0) / c)
|
|
67
68
|
)
|
|
68
69
|
}
|
|
69
70
|
), e;
|
|
70
|
-
}, [
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}, [
|
|
74
|
-
if (
|
|
75
|
-
const [e, t] =
|
|
76
|
-
e && (t ?
|
|
71
|
+
}, [n, L] = S(ue()), K = Ve(), fe = we(), k = Ce(), T = xe(), j = Se(), { isLoggedIn: x, isLoggingIn: Q } = Ae();
|
|
72
|
+
y(() => {
|
|
73
|
+
Q === !1 && (x ? ve(g) : p(!1));
|
|
74
|
+
}, [Q, x]), y(() => {
|
|
75
|
+
if (C === !1 && !B) {
|
|
76
|
+
const [e, t] = me();
|
|
77
|
+
e && (t ? P(t) : v(!0));
|
|
77
78
|
}
|
|
78
|
-
}, [
|
|
79
|
-
|
|
80
|
-
}, [l])
|
|
81
|
-
|
|
79
|
+
}, [C]), y(() => {
|
|
80
|
+
V && V(l);
|
|
81
|
+
}, [l]), y(() => {
|
|
82
|
+
ae?.({ total: c, counts: n });
|
|
83
|
+
}, [c, n]);
|
|
84
|
+
const me = () => {
|
|
82
85
|
if (_ && Object.keys(_).length !== 0)
|
|
83
|
-
return _.groupId ===
|
|
86
|
+
return _.groupId === g && _.voteableType === h ? [!0, _.positionId] : (J(), [!1, !1]);
|
|
84
87
|
const e = new URLSearchParams(
|
|
85
|
-
typeof window < "u" ? window.location.search :
|
|
88
|
+
typeof window < "u" ? window.location.search : fe.search
|
|
86
89
|
), t = !!e.get("initVote"), a = Number.parseInt(e.get("positionId")) || !1;
|
|
87
90
|
return [t, a];
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
t.data.data.resource ? (
|
|
91
|
+
}, ve = (e) => {
|
|
92
|
+
p(!0), V && V(l), k.getOneWithToken("votes", `${h.toLowerCase()}/${e}`, {}).then((t) => {
|
|
93
|
+
t.data.data.resource ? (R(t.data.data.resource), v(!0), p(!1)) : (p(!1), v(!1));
|
|
91
94
|
}).catch((t) => {
|
|
92
|
-
|
|
95
|
+
p(!1);
|
|
93
96
|
});
|
|
94
|
-
},
|
|
97
|
+
}, A = (e, t) => t === 0 ? 0 : Math.round(100 * (e / t)), X = ({ counts: e, total: t, vote: a }) => {
|
|
98
|
+
L(e), G(t), R(a);
|
|
99
|
+
}, he = (e) => {
|
|
95
100
|
const t = {
|
|
96
|
-
voteable_id:
|
|
97
|
-
voteable_type:
|
|
101
|
+
voteable_id: g,
|
|
102
|
+
voteable_type: h || "Group",
|
|
98
103
|
position_id: e
|
|
99
104
|
};
|
|
100
|
-
|
|
101
|
-
groupId:
|
|
102
|
-
voteableType:
|
|
105
|
+
le({
|
|
106
|
+
groupId: g,
|
|
107
|
+
voteableType: h,
|
|
103
108
|
positionId: e
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
})) : (me(e), k(), R.create("votes", t).then((n) => {
|
|
113
|
-
n.data.success && (M(n.data.data.resource), W(
|
|
114
|
-
C.formatMessage({
|
|
109
|
+
});
|
|
110
|
+
const r = {
|
|
111
|
+
counts: n,
|
|
112
|
+
total: c,
|
|
113
|
+
vote: l
|
|
114
|
+
}, f = (ee) => {
|
|
115
|
+
ee.data.success ? (R(ee.data.data.resource), de(
|
|
116
|
+
j.formatMessage({
|
|
115
117
|
id: "header.vote_confirm_modal",
|
|
116
118
|
defaultMessage: "Your vote has been saved !"
|
|
117
119
|
}),
|
|
118
120
|
{ type: "success" }
|
|
119
|
-
));
|
|
120
|
-
}));
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
)) : X(r);
|
|
122
|
+
}, b = () => X(r);
|
|
123
|
+
l ? (pe(e, l.position_id), N === !1 && F(), e !== l.position_id && k.update("votes", l.id, t).then(f, b)) : (ge(e), F(), k.create("votes", t).then(f, b));
|
|
124
|
+
}, ge = (e) => {
|
|
125
|
+
const t = n[e].count + 1, a = c + 1, r = {};
|
|
126
|
+
i.forEach((f) => {
|
|
127
|
+
if (e === f.id)
|
|
128
|
+
r[f.id] = {
|
|
126
129
|
count: t,
|
|
127
|
-
percentage:
|
|
130
|
+
percentage: A(t, a)
|
|
128
131
|
};
|
|
129
132
|
else {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
count:
|
|
133
|
-
percentage:
|
|
133
|
+
const b = n[f.id].count;
|
|
134
|
+
r[f.id] = {
|
|
135
|
+
count: b,
|
|
136
|
+
percentage: A(b, a)
|
|
134
137
|
};
|
|
135
138
|
}
|
|
136
|
-
}),
|
|
137
|
-
},
|
|
139
|
+
}), L(r), G(a);
|
|
140
|
+
}, pe = (e, t) => {
|
|
138
141
|
if (t !== e) {
|
|
139
142
|
const a = {
|
|
140
|
-
...
|
|
143
|
+
...n,
|
|
141
144
|
[t]: {
|
|
142
|
-
count:
|
|
143
|
-
percentage:
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
count: n[t].count - 1,
|
|
146
|
+
percentage: A(
|
|
147
|
+
n[t].count - 1,
|
|
148
|
+
c
|
|
146
149
|
)
|
|
147
150
|
},
|
|
148
151
|
[e]: {
|
|
149
|
-
count:
|
|
150
|
-
percentage:
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
count: n[e].count + 1,
|
|
153
|
+
percentage: A(
|
|
154
|
+
n[e].count + 1,
|
|
155
|
+
c
|
|
153
156
|
)
|
|
154
157
|
}
|
|
155
158
|
};
|
|
156
|
-
|
|
159
|
+
L(a);
|
|
157
160
|
}
|
|
158
|
-
},
|
|
161
|
+
}, Z = (e) => {
|
|
159
162
|
const t = new URLSearchParams({
|
|
160
163
|
initVote: "true",
|
|
161
164
|
...e && { positionId: e }
|
|
162
165
|
});
|
|
163
|
-
return
|
|
164
|
-
},
|
|
165
|
-
|
|
166
|
-
groupId:
|
|
167
|
-
voteableType:
|
|
166
|
+
return B + `?${t.toString()}`;
|
|
167
|
+
}, P = (e) => {
|
|
168
|
+
C || (x ? Object.keys(n).includes(e.toString()) && (he(e), J()) : (Object.keys(n).includes(e.toString()) && ie({
|
|
169
|
+
groupId: g,
|
|
170
|
+
voteableType: h,
|
|
168
171
|
positionId: e
|
|
169
|
-
}),
|
|
170
|
-
},
|
|
171
|
-
|
|
172
|
-
},
|
|
172
|
+
}), K({ loginAction: "vote" })));
|
|
173
|
+
}, F = () => {
|
|
174
|
+
N && ce(), v(!N);
|
|
175
|
+
}, Ne = (e, t) => {
|
|
173
176
|
let a;
|
|
174
|
-
t === 0 ? a =
|
|
175
|
-
const
|
|
177
|
+
t === 0 ? a = W.translatedContent : t === 1 ? a = Y.translatedContent : t === 2 && (a = z.translatedContent);
|
|
178
|
+
const r = typeof window < "u" && !B;
|
|
176
179
|
return /* @__PURE__ */ s(
|
|
177
180
|
"div",
|
|
178
181
|
{
|
|
179
|
-
className:
|
|
182
|
+
className: u(o.voteAction, {
|
|
180
183
|
[o.buttonAlignLeft]: o.buttonAlignLeft
|
|
181
184
|
}),
|
|
182
185
|
children: /* @__PURE__ */ s(
|
|
183
|
-
|
|
186
|
+
Re,
|
|
184
187
|
{
|
|
185
188
|
"data-tid": "action_vote",
|
|
186
189
|
type: "button",
|
|
187
190
|
title: a,
|
|
188
|
-
className:
|
|
189
|
-
[o.textAlignLeft]:
|
|
190
|
-
[
|
|
191
|
+
className: u(o.voteButton, {
|
|
192
|
+
[o.textAlignLeft]: oe,
|
|
193
|
+
[$]: $
|
|
191
194
|
}),
|
|
192
|
-
onClick:
|
|
193
|
-
disabled:
|
|
195
|
+
onClick: r ? () => P(e.id) : null,
|
|
196
|
+
disabled: M || r && C,
|
|
194
197
|
"data-testid": "voteButton",
|
|
195
|
-
to:
|
|
196
|
-
target:
|
|
197
|
-
rel:
|
|
198
|
-
external:
|
|
198
|
+
to: r ? null : Z(e.id),
|
|
199
|
+
target: r ? null : "_top",
|
|
200
|
+
rel: r ? null : "nofollow",
|
|
201
|
+
external: r ? null : !0,
|
|
199
202
|
children: /* @__PURE__ */ s(
|
|
200
203
|
"div",
|
|
201
204
|
{
|
|
202
205
|
"data-tid": "action_vote",
|
|
203
|
-
className:
|
|
204
|
-
[o.voteButtonThesisSynthesisMobile]: !
|
|
206
|
+
className: u(o.voteButtonThesis, {
|
|
207
|
+
[o.voteButtonThesisSynthesisMobile]: !I
|
|
205
208
|
}),
|
|
206
209
|
children: a
|
|
207
210
|
}
|
|
@@ -211,21 +214,21 @@ const We = ({
|
|
|
211
214
|
},
|
|
212
215
|
t
|
|
213
216
|
);
|
|
214
|
-
},
|
|
215
|
-
x ||
|
|
217
|
+
}, _e = () => {
|
|
218
|
+
x || T.actions?.unloggedVoteResults === !0 ? v(!0) : K({ loginAction: "vote" });
|
|
216
219
|
};
|
|
217
220
|
return /* @__PURE__ */ s(
|
|
218
221
|
"div",
|
|
219
222
|
{
|
|
220
|
-
className:
|
|
221
|
-
children: /* @__PURE__ */ s(
|
|
222
|
-
/* @__PURE__ */ s("div", { className: o.voteResults, children:
|
|
223
|
+
className: u(o.voteBox, { [U]: U }),
|
|
224
|
+
children: /* @__PURE__ */ s(be, { children: N || M ? /* @__PURE__ */ d("div", { className: o.voteResultsBox, "data-testid": "voteResultsBox", children: [
|
|
225
|
+
/* @__PURE__ */ s("div", { className: o.voteResults, children: i.map((e, t) => {
|
|
223
226
|
let a;
|
|
224
|
-
return t === 0 ? a =
|
|
225
|
-
/* @__PURE__ */
|
|
227
|
+
return t === 0 ? a = W.translatedContent : t === 1 ? a = Y.translatedContent : t === 2 && (a = z.translatedContent), /* @__PURE__ */ d("div", { children: [
|
|
228
|
+
/* @__PURE__ */ d(
|
|
226
229
|
"div",
|
|
227
230
|
{
|
|
228
|
-
className: t > 0 ?
|
|
231
|
+
className: t > 0 ? u(
|
|
229
232
|
o.voteProgressHeader,
|
|
230
233
|
o.voteProgressHeaderAgainst
|
|
231
234
|
) : o.voteProgressHeader,
|
|
@@ -235,64 +238,64 @@ const We = ({
|
|
|
235
238
|
l && l.position_id === e.id ? /* @__PURE__ */ s(
|
|
236
239
|
"span",
|
|
237
240
|
{
|
|
238
|
-
title:
|
|
241
|
+
title: j.formatMessage({
|
|
239
242
|
id: "vote.vote_box.vote_side"
|
|
240
243
|
}) + a,
|
|
241
244
|
className: o.sideIcon,
|
|
242
245
|
"aria-hidden": "true",
|
|
243
|
-
children: /* @__PURE__ */ s(
|
|
246
|
+
children: /* @__PURE__ */ s(E, { name: "checkbox", width: 16, height: 16 })
|
|
244
247
|
}
|
|
245
248
|
) : null
|
|
246
249
|
]
|
|
247
250
|
}
|
|
248
251
|
),
|
|
249
|
-
/* @__PURE__ */
|
|
250
|
-
|
|
252
|
+
/* @__PURE__ */ d(
|
|
253
|
+
ye,
|
|
251
254
|
{
|
|
252
|
-
progress:
|
|
255
|
+
progress: n[e.id].percentage / 100,
|
|
253
256
|
goal: 1,
|
|
254
257
|
className: o.progress,
|
|
255
258
|
innerClassName: o.progressBar,
|
|
256
259
|
children: [
|
|
257
|
-
|
|
260
|
+
n[e.id].percentage,
|
|
258
261
|
"%"
|
|
259
262
|
]
|
|
260
263
|
}
|
|
261
264
|
)
|
|
262
265
|
] }, t);
|
|
263
266
|
}) }),
|
|
264
|
-
/* @__PURE__ */
|
|
265
|
-
|
|
266
|
-
|
|
267
|
+
/* @__PURE__ */ d("div", { className: o.voteBoxFooter, children: [
|
|
268
|
+
se && /* @__PURE__ */ s("div", { className: o.voteResultsNumberVoters, children: /* @__PURE__ */ s(
|
|
269
|
+
m,
|
|
267
270
|
{
|
|
268
271
|
id: "vote.vote_box.votes",
|
|
269
|
-
values: { votesCount:
|
|
272
|
+
values: { votesCount: c },
|
|
270
273
|
defaultMessage: "{votesCount} votes"
|
|
271
274
|
}
|
|
272
275
|
) }),
|
|
273
|
-
!
|
|
276
|
+
!M && /* @__PURE__ */ s("div", { children: l ? /* @__PURE__ */ s(
|
|
274
277
|
"button",
|
|
275
278
|
{
|
|
276
279
|
"data-tid": "action_edit_vote",
|
|
277
280
|
className: o.voteActionButton,
|
|
278
281
|
type: "button",
|
|
279
|
-
onClick:
|
|
282
|
+
onClick: F,
|
|
280
283
|
children: /* @__PURE__ */ s(
|
|
281
|
-
|
|
284
|
+
m,
|
|
282
285
|
{
|
|
283
286
|
id: "vote.vote_box.update",
|
|
284
287
|
defaultMessage: "Modify"
|
|
285
288
|
}
|
|
286
289
|
)
|
|
287
290
|
}
|
|
288
|
-
) :
|
|
291
|
+
) : !D && /* @__PURE__ */ s(
|
|
289
292
|
"button",
|
|
290
293
|
{
|
|
291
294
|
type: "button",
|
|
292
295
|
className: o.voteActionButton,
|
|
293
|
-
onClick: () =>
|
|
296
|
+
onClick: () => v(!1),
|
|
294
297
|
children: /* @__PURE__ */ s(
|
|
295
|
-
|
|
298
|
+
m,
|
|
296
299
|
{
|
|
297
300
|
id: "vote.vote_box.back",
|
|
298
301
|
defaultMessage: "Back to vote"
|
|
@@ -301,40 +304,40 @@ const We = ({
|
|
|
301
304
|
}
|
|
302
305
|
) })
|
|
303
306
|
] })
|
|
304
|
-
] }) : /* @__PURE__ */
|
|
307
|
+
] }) : /* @__PURE__ */ d("div", { className: o.voteBoxActions, children: [
|
|
305
308
|
/* @__PURE__ */ s(
|
|
306
309
|
"div",
|
|
307
310
|
{
|
|
308
|
-
className:
|
|
309
|
-
[o.voteBoxActionsBodyColumn]:
|
|
310
|
-
[o.voteBoxActionsBodyOutlined]:
|
|
311
|
-
[o.voteBoxActionsBodyFilledNeutral]:
|
|
312
|
-
[
|
|
311
|
+
className: u(o.voteBoxActionsBody, {
|
|
312
|
+
[o.voteBoxActionsBodyColumn]: I,
|
|
313
|
+
[o.voteBoxActionsBodyOutlined]: T.layout?.outlinedVoteButtons,
|
|
314
|
+
[o.voteBoxActionsBodyFilledNeutral]: T.layout?.filledNeutralVoteButton,
|
|
315
|
+
[H]: H
|
|
313
316
|
}),
|
|
314
|
-
children:
|
|
315
|
-
(e, t) =>
|
|
317
|
+
children: i.map(
|
|
318
|
+
(e, t) => Ne(e, t)
|
|
316
319
|
)
|
|
317
320
|
}
|
|
318
321
|
),
|
|
319
|
-
|
|
320
|
-
/* @__PURE__ */
|
|
321
|
-
/* @__PURE__ */ s(
|
|
322
|
+
ne && /* @__PURE__ */ d("div", { className: o.voteCommentCounts, children: [
|
|
323
|
+
/* @__PURE__ */ d("div", { className: o.debateNumberItem, children: [
|
|
324
|
+
/* @__PURE__ */ s(E, { name: "votebox", width: 20, height: 20 }),
|
|
322
325
|
/* @__PURE__ */ s("div", { className: o.debateNumberLabel, children: /* @__PURE__ */ s(
|
|
323
|
-
|
|
326
|
+
m,
|
|
324
327
|
{
|
|
325
328
|
id: "vote.vote_box.votes",
|
|
326
|
-
values: { votesCount:
|
|
329
|
+
values: { votesCount: c },
|
|
327
330
|
defaultMessage: "{votesCount} votes"
|
|
328
331
|
}
|
|
329
332
|
) })
|
|
330
333
|
] }),
|
|
331
|
-
/* @__PURE__ */
|
|
332
|
-
/* @__PURE__ */ s(
|
|
334
|
+
/* @__PURE__ */ d("div", { className: o.debateNumberItem, children: [
|
|
335
|
+
/* @__PURE__ */ s(E, { name: "chat", width: 20, height: 20 }),
|
|
333
336
|
/* @__PURE__ */ s("div", { className: o.debateNumberLabel, children: /* @__PURE__ */ s(
|
|
334
|
-
|
|
337
|
+
m,
|
|
335
338
|
{
|
|
336
339
|
id: "vote.vote_box.comments",
|
|
337
|
-
values: { count:
|
|
340
|
+
values: { count: re ?? 0 },
|
|
338
341
|
defaultMessage: "{count} comments"
|
|
339
342
|
}
|
|
340
343
|
) })
|
|
@@ -343,24 +346,24 @@ const We = ({
|
|
|
343
346
|
/* @__PURE__ */ s(
|
|
344
347
|
"div",
|
|
345
348
|
{
|
|
346
|
-
className:
|
|
349
|
+
className: u(
|
|
347
350
|
o.voteBoxActions,
|
|
348
351
|
o.voteBoxShowResultContainer,
|
|
349
|
-
{ [
|
|
352
|
+
{ [q]: q }
|
|
350
353
|
),
|
|
351
|
-
children: /* @__PURE__ */ s("div", { className: o.voteBoxShowResult, children:
|
|
354
|
+
children: /* @__PURE__ */ s("div", { className: o.voteBoxShowResult, children: D ? !N && /* @__PURE__ */ s("div", { className: o.voteResultInfoText, children: j.formatMessage({
|
|
352
355
|
id: "vote.vote_box.result_after_vote",
|
|
353
356
|
defaultMessage: "Le résultat s'affichera après le vote."
|
|
354
|
-
}) }) : typeof window < "u" && !
|
|
357
|
+
}) }) : typeof window < "u" && !B ? /* @__PURE__ */ s(
|
|
355
358
|
"button",
|
|
356
359
|
{
|
|
357
360
|
type: "button",
|
|
358
|
-
onClick:
|
|
361
|
+
onClick: _e,
|
|
359
362
|
"data-tid": "show_vote_result",
|
|
360
363
|
"data-testid": "show-result",
|
|
361
364
|
className: o.showResultButton,
|
|
362
|
-
children: /* @__PURE__ */ s("span", { className:
|
|
363
|
-
|
|
365
|
+
children: /* @__PURE__ */ s("span", { className: u(o.boldShowResult, o.outlined), children: /* @__PURE__ */ s(
|
|
366
|
+
m,
|
|
364
367
|
{
|
|
365
368
|
id: "vote.vote_box.show_result",
|
|
366
369
|
defaultMessage: "Show result"
|
|
@@ -368,16 +371,16 @@ const We = ({
|
|
|
368
371
|
) })
|
|
369
372
|
}
|
|
370
373
|
) : /* @__PURE__ */ s(
|
|
371
|
-
|
|
374
|
+
Me,
|
|
372
375
|
{
|
|
373
|
-
to:
|
|
376
|
+
to: Z(null),
|
|
374
377
|
rel: "nofollow",
|
|
375
378
|
"data-tid": "show_vote_result",
|
|
376
379
|
target: "_top",
|
|
377
380
|
external: !0,
|
|
378
381
|
"data-testid": "show-result",
|
|
379
|
-
children: /* @__PURE__ */ s("span", { className:
|
|
380
|
-
|
|
382
|
+
children: /* @__PURE__ */ s("span", { className: u(o.boldShowResult, o.outlined), children: /* @__PURE__ */ s(
|
|
383
|
+
m,
|
|
381
384
|
{
|
|
382
385
|
id: "vote.vote_box.show_result",
|
|
383
386
|
defaultMessage: "Show result"
|
|
@@ -392,5 +395,5 @@ const We = ({
|
|
|
392
395
|
);
|
|
393
396
|
};
|
|
394
397
|
export {
|
|
395
|
-
|
|
398
|
+
Ke as VoteBox
|
|
396
399
|
};
|
package/dist/index.js
CHANGED
|
@@ -133,7 +133,7 @@ import { classes as rx, getAccent as ex } from "./components/input/text_input/co
|
|
|
133
133
|
import { dataProvider as xx } from "./components/data/data_provider/DataProvider.js";
|
|
134
134
|
import { extractFormData as px } from "./components/forms/form/extract-form-data.js";
|
|
135
135
|
import { getTranslatedContent as nx, useTranslatedContent as ax } from "./components/translation/translated_content/useTranslatedContent.js";
|
|
136
|
-
import { httpClient as sx } from "./components/data/
|
|
136
|
+
import { httpClient as sx } from "./components/data/http_client/httpClient.js";
|
|
137
137
|
import { lexicalToHtml as dx } from "./components/input/text_editor/lexicalToHtml.js";
|
|
138
138
|
import { makeStorage as gx } from "./components/auth/use_auth/AuthStorage.js";
|
|
139
139
|
import { uniqueBy as Bx } from "./components/util/unique_by/uniqueBy.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logora/debate",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.94",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"description": "Design system of @Logora made with React",
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"@lexical/selection": "^0.45.0",
|
|
53
53
|
"@lexical/utils": "^0.45.0",
|
|
54
54
|
"@rooks/use-previous": "^4.11.2",
|
|
55
|
-
"axios": "^1.15.2",
|
|
56
55
|
"chart.js": "^4.5.1",
|
|
57
56
|
"chartjs-plugin-datalabels": "^2.2.0",
|
|
58
57
|
"classnames": "^2.5.1",
|