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