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