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