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