@logora/debate 0.4.79 → 0.4.80
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,26 +1,26 @@
|
|
|
1
|
-
import { jsxs as U, jsx as
|
|
1
|
+
import { jsxs as U, jsx as u, Fragment as Qe } from "react/jsx-runtime";
|
|
2
2
|
import Ue from "@rooks/use-previous";
|
|
3
3
|
import $e from "classnames";
|
|
4
|
-
import
|
|
5
|
-
import { useIntl as
|
|
6
|
-
import { useLocation as
|
|
4
|
+
import Ie, { useState as c, useEffect as p } from "react";
|
|
5
|
+
import { useIntl as We } from "react-intl";
|
|
6
|
+
import { useLocation as ze } from "react-router";
|
|
7
7
|
import l from "./PaginatedList.module.scss.js";
|
|
8
|
-
import { ActionBar as
|
|
9
|
-
import { useList as
|
|
10
|
-
import { useDataProvider as
|
|
11
|
-
import { useResponsive as
|
|
12
|
-
import { useData as
|
|
8
|
+
import { ActionBar as Ge } from "./action_bar/ActionBar.js";
|
|
9
|
+
import { useList as Pe } from "../list_provider/useList.js";
|
|
10
|
+
import { useDataProvider as Ve } from "../../data/data_provider/useDataProvider.js";
|
|
11
|
+
import { useResponsive as Xe } from "../../hooks/use_responsive/useResponsive.js";
|
|
12
|
+
import { useData as Ye } from "../../data/data_provider/useData.js";
|
|
13
13
|
import { uniqueBy as x } from "../../util/unique_by/uniqueBy.js";
|
|
14
|
-
import { Pagination as
|
|
15
|
-
import { StandardErrorBoundary as
|
|
14
|
+
import { Pagination as Ze } from "../pagination/Pagination.js";
|
|
15
|
+
import { StandardErrorBoundary as He } from "../../error/standard_error_boundary/StandardErrorBoundary.js";
|
|
16
16
|
const ct = ({
|
|
17
17
|
query: N,
|
|
18
18
|
sortOptions: o,
|
|
19
|
-
sort:
|
|
19
|
+
sort: b,
|
|
20
20
|
filters: m,
|
|
21
21
|
tagList: ne,
|
|
22
22
|
pinnedTagList: ae,
|
|
23
|
-
currentPage:
|
|
23
|
+
currentPage: M,
|
|
24
24
|
resource: A,
|
|
25
25
|
currentListId: a,
|
|
26
26
|
withToken: le,
|
|
@@ -32,48 +32,50 @@ const ct = ({
|
|
|
32
32
|
tagParam: re = "tag_id",
|
|
33
33
|
totalHeaderParam: D = "total",
|
|
34
34
|
onUpdateTotal: $,
|
|
35
|
-
onElementsLoad:
|
|
36
|
-
transformData:
|
|
35
|
+
onElementsLoad: R,
|
|
36
|
+
transformData: I,
|
|
37
37
|
uniqueIdKey: S = "id",
|
|
38
38
|
children: fe,
|
|
39
39
|
resourcePropName: ce,
|
|
40
|
-
loadingComponent:
|
|
41
|
-
searchBar:
|
|
42
|
-
title:
|
|
40
|
+
loadingComponent: W,
|
|
41
|
+
searchBar: ge = !1,
|
|
42
|
+
title: ue,
|
|
43
43
|
subtitle: Ee,
|
|
44
44
|
showDebateConsultationSubtitle: he = !1,
|
|
45
|
-
emptyListComponent:
|
|
46
|
-
emptyText:
|
|
47
|
-
display:
|
|
48
|
-
elementsPerLine:
|
|
45
|
+
emptyListComponent: z,
|
|
46
|
+
emptyText: G,
|
|
47
|
+
display: P,
|
|
48
|
+
elementsPerLine: V,
|
|
49
49
|
indexLayout: pe = !1,
|
|
50
50
|
gap: ve = "1em",
|
|
51
51
|
withPagination: Se = !0,
|
|
52
|
-
numberElements:
|
|
52
|
+
numberElements: X,
|
|
53
53
|
countless: ye,
|
|
54
54
|
onElementClick: we,
|
|
55
55
|
withUrlParams: Ne = !1,
|
|
56
|
-
onLoadNewPage:
|
|
56
|
+
onLoadNewPage: Y
|
|
57
57
|
}) => {
|
|
58
|
-
const J =
|
|
59
|
-
|
|
60
|
-
), [
|
|
61
|
-
|
|
62
|
-
),
|
|
58
|
+
const J = We(), t = Pe(), Z = Ve(), H = ze(), { isMobile: K, isTablet: be, isDesktop: L } = Xe(), d = new URLSearchParams(
|
|
59
|
+
typeof window < "u" ? window.location.search : H.search
|
|
60
|
+
), [k, E] = c(!1), [Me, Re] = c(!1), [r, y] = Ye(a, []), [O, ke] = c(
|
|
61
|
+
r?.length || 0
|
|
62
|
+
), [h, j] = c(M || 1), [w, B] = c(N || null), [C, q] = c(
|
|
63
|
+
d.get("tagId") ? Number.parseInt(d.get("tagId"), 10) : null
|
|
64
|
+
), [Ce, ee] = c(null), Te = () => o && o[0].type === "sort" && o[0].value || b || "", Fe = () => {
|
|
63
65
|
let e = {};
|
|
64
66
|
return o && o[0].type === "filter" && (e[o[0].name] = o[0].value), m && (e = Object.assign({}, e, m)), e;
|
|
65
|
-
}, [T, F] =
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
F(
|
|
69
|
-
for (const e of
|
|
67
|
+
}, [T, F] = c(Te()), [Q, _] = c(Fe()), te = Ue(m);
|
|
68
|
+
M && M !== h && j(M), N !== void 0 && N !== w && B(N), b !== void 0 && b !== T && F(b), te && JSON.stringify(m) !== JSON.stringify(te) && JSON.stringify(m) !== JSON.stringify(Q) && _(m), p(() => {
|
|
69
|
+
if (d.get("tagId") && q(Number.parseInt(d.get("tagId"))), d.get("search") && B(d.get("search")), d.get("sort")) {
|
|
70
|
+
F(d.get("sort"));
|
|
71
|
+
for (const e of d.values()) {
|
|
70
72
|
o?.map((s) => {
|
|
71
73
|
s.value === e && ee(s.name);
|
|
72
74
|
});
|
|
73
75
|
break;
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
|
-
for (const e of
|
|
78
|
+
for (const e of d.keys()) {
|
|
77
79
|
o?.map((s) => {
|
|
78
80
|
s.name === e && (_({
|
|
79
81
|
...m,
|
|
@@ -82,7 +84,7 @@ const ct = ({
|
|
|
82
84
|
});
|
|
83
85
|
break;
|
|
84
86
|
}
|
|
85
|
-
}, [
|
|
87
|
+
}, [H.search]), p(() => {
|
|
86
88
|
A ? (j(1), y([]), E(!0), se(1)) : E(!1);
|
|
87
89
|
}, [
|
|
88
90
|
T,
|
|
@@ -104,34 +106,34 @@ const ct = ({
|
|
|
104
106
|
const e = t.updateElements[a];
|
|
105
107
|
if (e.length > 0) {
|
|
106
108
|
const s = e.filter(
|
|
107
|
-
(i) =>
|
|
109
|
+
(i) => r.some((n) => n.id === i.id)
|
|
108
110
|
);
|
|
109
111
|
if (s.length > 0) {
|
|
110
112
|
De(s);
|
|
111
113
|
const i = e.filter(
|
|
112
|
-
(
|
|
114
|
+
(f) => !r.some((g) => g.id === f.id)
|
|
113
115
|
), n = { ...t.updateElements };
|
|
114
116
|
i.length > 0 ? n[a] = i : delete n[a], t.setUpdateElements(n);
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
|
-
}, [t.updateElements,
|
|
119
|
-
if (t.removeElements && a in t.removeElements && t.removeElements[a].length > 0 &&
|
|
120
|
+
}, [t.updateElements, r]), p(() => {
|
|
121
|
+
if (t.removeElements && a in t.removeElements && t.removeElements[a].length > 0 && r.length > 0) {
|
|
120
122
|
Je(t.removeElements[a]);
|
|
121
123
|
const e = { ...t.removeElements };
|
|
122
124
|
delete e[a], t.setRemoveElements(e);
|
|
123
125
|
}
|
|
124
|
-
}, [t.removeElements,
|
|
126
|
+
}, [t.removeElements, r]);
|
|
125
127
|
const _e = (e) => {
|
|
126
128
|
e.type === "filter" ? (F(""), _({
|
|
127
129
|
...m,
|
|
128
130
|
[e.name]: e.value
|
|
129
131
|
})) : (F(e.value), _(m ? { ...m } : {}));
|
|
130
132
|
}, xe = () => {
|
|
131
|
-
typeof
|
|
133
|
+
typeof Y == "function" && Y() !== null || j(h + 1);
|
|
132
134
|
}, se = (e) => {
|
|
133
|
-
const s = le ?
|
|
134
|
-
if ((e - 1) * v <= (
|
|
135
|
+
const s = le ? Z.getListWithToken : Z.getList;
|
|
136
|
+
if ((e - 1) * v <= (X || O) || e === 1) {
|
|
135
137
|
const i = {
|
|
136
138
|
[oe]: e,
|
|
137
139
|
[ie]: v,
|
|
@@ -142,32 +144,32 @@ const ct = ({
|
|
|
142
144
|
...C && { [re]: C }
|
|
143
145
|
};
|
|
144
146
|
s(A, i).then((n) => {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
Number.parseInt(
|
|
148
|
-
), $ && $(
|
|
149
|
-
let
|
|
150
|
-
|
|
147
|
+
const f = n.headers;
|
|
148
|
+
f && D in f && (ke(
|
|
149
|
+
Number.parseInt(f[D || "total"], 10)
|
|
150
|
+
), $ && $(f[D || "total"]));
|
|
151
|
+
let g = n?.data?.data;
|
|
152
|
+
R && R(g), I && (g = g.filter(I)), t.addElements && a in t.addElements && t.addElements[a].length > 0 && (g = [...t.addElements[a], g]), Le(g), E(!1);
|
|
151
153
|
}).catch((n) => {
|
|
152
|
-
console.error(n), n?.response?.status !== 404 &&
|
|
154
|
+
console.error(n), n?.response?.status !== 404 && Re(!0), E(!1);
|
|
153
155
|
});
|
|
154
156
|
} else
|
|
155
157
|
E(!1);
|
|
156
158
|
}, Ae = (e) => {
|
|
157
159
|
y(
|
|
158
160
|
(s) => x([...e, ...s], S || "id")
|
|
159
|
-
),
|
|
161
|
+
), R && R(e);
|
|
160
162
|
}, De = (e) => {
|
|
161
163
|
y((s) => {
|
|
162
164
|
let i = s;
|
|
163
165
|
return e.forEach(
|
|
164
166
|
(n) => i = i.map(
|
|
165
|
-
(
|
|
167
|
+
(f) => f.id === n.id ? n : f
|
|
166
168
|
)
|
|
167
169
|
), x(i, S || "id");
|
|
168
170
|
});
|
|
169
171
|
}, Je = (e) => {
|
|
170
|
-
const s = e.map((n) => n.id), i =
|
|
172
|
+
const s = e.map((n) => n.id), i = r.filter(
|
|
171
173
|
(n) => s.indexOf(n.id) === -1
|
|
172
174
|
);
|
|
173
175
|
y(x(i, S || "id"));
|
|
@@ -175,20 +177,20 @@ const ct = ({
|
|
|
175
177
|
y(
|
|
176
178
|
(s) => x([...s, ...e], S || "id")
|
|
177
179
|
);
|
|
178
|
-
}, je = (e, s) => e !== void 0 ? /* @__PURE__ */
|
|
180
|
+
}, je = (e, s) => e !== void 0 ? /* @__PURE__ */ u(
|
|
179
181
|
"li",
|
|
180
182
|
{
|
|
181
183
|
className: l.paginatedListItem,
|
|
182
184
|
"data-testid": "list-item",
|
|
183
185
|
onClick: we,
|
|
184
|
-
children: /* @__PURE__ */
|
|
186
|
+
children: /* @__PURE__ */ u(He, { hideMessage: !0, children: Ie.cloneElement(fe, {
|
|
185
187
|
index: s,
|
|
186
188
|
[ce]: e
|
|
187
189
|
}) })
|
|
188
190
|
},
|
|
189
191
|
`${e[S || "id"]}_${e.updated_at || e.content}`
|
|
190
|
-
) : null, Be = (e) =>
|
|
191
|
-
if (
|
|
192
|
+
) : null, Be = (e) => W ? /* @__PURE__ */ u("li", { className: l.paginatedListItem, children: W }, e) : null;
|
|
193
|
+
if (Me)
|
|
192
194
|
throw new Error(
|
|
193
195
|
J.formatMessage({
|
|
194
196
|
id: "error.list",
|
|
@@ -196,15 +198,15 @@ const ct = ({
|
|
|
196
198
|
})
|
|
197
199
|
);
|
|
198
200
|
return /* @__PURE__ */ U("div", { className: l.listContainer, children: [
|
|
199
|
-
/* @__PURE__ */
|
|
200
|
-
|
|
201
|
+
/* @__PURE__ */ u(
|
|
202
|
+
Ge,
|
|
201
203
|
{
|
|
202
|
-
title:
|
|
204
|
+
title: ue,
|
|
203
205
|
subtitle: Ee,
|
|
204
206
|
showDebateConsultationSubtitle: he,
|
|
205
207
|
sortOptions: o,
|
|
206
208
|
defaultSelectOption: Ce,
|
|
207
|
-
searchBar:
|
|
209
|
+
searchBar: ge,
|
|
208
210
|
tagList: ne,
|
|
209
211
|
pinnedTagList: ae,
|
|
210
212
|
activeTagId: C,
|
|
@@ -214,7 +216,7 @@ const ct = ({
|
|
|
214
216
|
withUrlParams: Ne
|
|
215
217
|
}
|
|
216
218
|
),
|
|
217
|
-
!k &&
|
|
219
|
+
!k && r.length === 0 ? z ? /* @__PURE__ */ u("div", { className: l.emptyListElement, children: z }) : /* @__PURE__ */ u("div", { className: l.emptyList, children: G || J.formatMessage({
|
|
218
220
|
id: "info.emptyList",
|
|
219
221
|
defaultMessage: "No items for now."
|
|
220
222
|
}) }) : /* @__PURE__ */ U(Qe, { children: [
|
|
@@ -223,24 +225,24 @@ const ct = ({
|
|
|
223
225
|
{
|
|
224
226
|
className: $e(l.paginatedList, {
|
|
225
227
|
[l.paginatedListIsTablet]: !K && !L,
|
|
226
|
-
[l.centeredList]:
|
|
227
|
-
[l.column]:
|
|
228
|
-
[l.twoElementsPerLine]:
|
|
229
|
-
[l.oneElementPerLine]:
|
|
228
|
+
[l.centeredList]: P === "column",
|
|
229
|
+
[l.column]: P === "column",
|
|
230
|
+
[l.twoElementsPerLine]: V === 2,
|
|
231
|
+
[l.oneElementPerLine]: V === 1,
|
|
230
232
|
[l.indexLayoutList]: pe,
|
|
231
233
|
[l.listIsDesktop]: L,
|
|
232
|
-
[l.listIsTablet]:
|
|
234
|
+
[l.listIsTablet]: be && !L,
|
|
233
235
|
[l.listIsMobile]: K
|
|
234
236
|
}),
|
|
235
237
|
style: { gap: ve },
|
|
236
238
|
children: [
|
|
237
|
-
|
|
239
|
+
r.map(je),
|
|
238
240
|
k ? Array(v).fill().map((e, s) => s).map(Be) : null
|
|
239
241
|
]
|
|
240
242
|
}
|
|
241
243
|
),
|
|
242
|
-
!k && Se !== !1 && /* @__PURE__ */
|
|
243
|
-
|
|
244
|
+
!k && Se !== !1 && /* @__PURE__ */ u(
|
|
245
|
+
Ze,
|
|
244
246
|
{
|
|
245
247
|
buttonText: J.formatMessage({
|
|
246
248
|
id: "action.see_more",
|
|
@@ -248,7 +250,7 @@ const ct = ({
|
|
|
248
250
|
}),
|
|
249
251
|
currentPage: h,
|
|
250
252
|
perPage: v,
|
|
251
|
-
totalElements:
|
|
253
|
+
totalElements: X || O,
|
|
252
254
|
onLoad: xe,
|
|
253
255
|
isLoading: k,
|
|
254
256
|
hideLoader: !0,
|