@logora/debate 0.3.96 → 0.3.98

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 c, Fragment as Qe } from "react/jsx-runtime";
1
+ import { jsxs as $, jsx as u, Fragment as Qe } from "react/jsx-runtime";
2
2
  import $e from "@rooks/use-previous";
3
- import Pe from "classnames";
4
- import Ue, { useState as m, useEffect as h } from "react";
5
- import { useIntl as We } from "react-intl";
6
- import { useLocation as ze } from "react-router";
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 Ge } from "./action_bar/ActionBar.js";
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: w,
17
+ query: N,
18
18
  sortOptions: i,
19
- sort: N,
19
+ sort: M,
20
20
  filters: o,
21
21
  tagList: ne,
22
22
  pinnedTagList: ae,
23
- currentPage: M,
23
+ currentPage: R,
24
24
  resource: A,
25
25
  currentListId: n,
26
26
  withToken: le,
27
- perPage: p,
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: P,
35
- onElementsLoad: R,
36
- transformData: U,
37
- uniqueIdKey: v = "id",
34
+ onUpdateTotal: U,
35
+ onElementsLoad: b,
36
+ transformData: W,
37
+ uniqueIdKey: S = "id",
38
38
  children: fe,
39
39
  resourcePropName: ce,
40
- loadingComponent: W,
40
+ loadingComponent: z,
41
41
  searchBar: ue = !1,
42
42
  title: Ee,
43
43
  subtitle: ge,
44
44
  showDebateConsultationSubtitle: he = !1,
45
- emptyListComponent: z,
46
- emptyText: G,
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 = We(), t = Ve(), H = Xe(), I = ze(), { isMobile: K, isTablet: Me, isDesktop: j } = Ye(), [b, u] = m(!1), [Re, be] = m(!1), [k, S] = Ze(n, []), [O, ke] = m(
59
- k?.length || 0
60
- ), [E, B] = m(M || 1), [y, L] = m(w || null), [C, q] = m(null), [Ce, ee] = m(null), d = new URLSearchParams(
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 || N || "", Te = () => {
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
- M && M !== E && B(M), w !== void 0 && w !== y && L(w), N !== void 0 && N !== F && T(N), te && JSON.stringify(o) !== JSON.stringify(te) && JSON.stringify(o) !== JSON.stringify(Q) && _(o), h(() => {
67
- if (d.get("tagId") && q(Number.parseInt(d.get("tagId"))), d.get("search") && L(d.get("search")), d.get("sort")) {
68
- T(d.get("sort"));
69
- for (const e of d.values()) {
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 d.keys()) {
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]), h(() => {
86
- A ? (B(1), S([]), u(!0), se(1)) : u(!1);
85
+ }, [I.search]), p(() => {
86
+ A ? (j(1), y([]), E(!0), se(1)) : E(!1);
87
87
  }, [
88
88
  F,
89
89
  Q,
90
- y,
90
+ w,
91
91
  A,
92
92
  C,
93
- p
94
- ]), h(() => {
95
- E > 1 && (u(!0), se(E));
96
- }, [E]), h(() => {
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]), h(() => {
103
- if (t.updateElements && n in t.updateElements && (console.log("[PaginatedList] update received for listId:", n, t.updateElements[n]), t.updateElements[n].length > 0)) {
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]), h(() => {
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 || B(E + 1);
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) * p <= (Y || O) || e === 1) {
125
- const r = {
124
+ if ((e - 1) * v <= (Y || O) || e === 1) {
125
+ const f = {
126
126
  [oe]: e,
127
- [ie]: p,
128
- ...F && !y && { [me]: F },
129
- ...y && { [de]: y },
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, r).then((l) => {
135
- const f = l.headers;
136
- f && D in f && (ke(
137
- Number.parseInt(f[D || "total"], 10)
138
- ), P && P(f[D || "total"]));
139
- let g = l?.data?.data;
140
- R && R(g), U && (g = g.filter(U)), t.addElements && n in t.addElements && t.addElements[n].length > 0 && (g = [...t.addElements[n], g]), je(g), u(!1);
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), u(!1);
142
+ console.error(l), l?.response?.status !== 404 && be(!0), E(!1);
143
143
  });
144
144
  } else
145
- u(!1);
145
+ E(!1);
146
146
  }, Ae = (e) => {
147
- S(
148
- (s) => x([...e, ...s], v || "id")
149
- ), R && R(e);
147
+ y(
148
+ (s) => x([...e, ...s], S || "id")
149
+ ), b && b(e);
150
150
  }, De = (e) => {
151
- S((s) => {
152
- let r = s;
151
+ y((s) => {
152
+ let f = s;
153
153
  return e.forEach(
154
- (l) => r = r.map(
155
- (f) => f.id === l.id ? l : f
154
+ (l) => f = f.map(
155
+ (c) => c.id === l.id ? l : c
156
156
  )
157
- ), x(r, v || "id");
157
+ ), x(f, S || "id");
158
158
  });
159
159
  }, Je = (e) => {
160
- const s = e.map((l) => l.id), r = k.filter(
160
+ const s = e.map((l) => l.id), f = d.filter(
161
161
  (l) => s.indexOf(l.id) === -1
162
162
  );
163
- S(x(r, v || "id"));
164
- }, je = (e) => {
165
- S(
166
- (s) => x([...s, ...e], v || "id")
163
+ y(x(f, S || "id"));
164
+ }, Le = (e) => {
165
+ y(
166
+ (s) => x([...s, ...e], S || "id")
167
167
  );
168
- }, Be = (e, s) => e !== void 0 ? /* @__PURE__ */ c(
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__ */ c(Ie, { hideMessage: !0, children: Ue.cloneElement(fe, {
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[v || "id"]}_${e.updated_at || e.content}`
180
- ) : null, Le = (e) => W ? /* @__PURE__ */ c("li", { className: a.paginatedListItem, children: W }, e) : 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__ */ c(
190
- Ge,
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) => L(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
- !b && k.length === 0 ? z ? /* @__PURE__ */ c("div", { className: a.emptyListElement, children: z }) : /* @__PURE__ */ c("div", { className: a.emptyList, children: G || J.formatMessage({
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: Pe(a.paginatedList, {
215
- [a.paginatedListIsTablet]: !K && !j,
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]: j,
222
- [a.listIsTablet]: Me && !j,
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
- k.map(Be),
228
- b ? Array(p).fill().map((e, s) => s).map(Le) : null
227
+ d.map(je),
228
+ k ? Array(v).fill().map((e, s) => s).map(Be) : null
229
229
  ]
230
230
  }
231
231
  ),
232
- !b && Se !== !1 && /* @__PURE__ */ c(
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: E,
240
- perPage: p,
239
+ currentPage: g,
240
+ perPage: v,
241
241
  totalElements: Y || O,
242
242
  onLoad: xe,
243
- isLoading: b,
243
+ isLoading: k,
244
244
  hideLoader: !0,
245
245
  "data-tid": "list_read_more"
246
246
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logora/debate",
3
- "version": "0.3.96",
3
+ "version": "0.3.98",
4
4
  "type": "module",
5
5
  "license": "AGPL-3.0",
6
6
  "description": "Design system of @Logora made with React",