@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 $, jsx as u, Fragment as Qe } from "react/jsx-runtime";
2
- import $e from "@rooks/use-previous";
3
- import Ue from "classnames";
4
- import We, { useState as m, useEffect as p } from "react";
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 a from "./PaginatedList.module.scss.js";
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: i,
18
+ sortOptions: o,
19
19
  sort: M,
20
- filters: o,
20
+ filters: m,
21
21
  tagList: ne,
22
22
  pinnedTagList: ae,
23
23
  currentPage: R,
24
24
  resource: A,
25
- currentListId: n,
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: U,
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: Ee,
43
- subtitle: ge,
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] = m(!1), [Re, be] = m(!1), [d, y] = Ze(n, []), [O, ke] = m(
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
- ), [g, j] = m(R || 1), [w, B] = m(N || null), [C, q] = m(null), [Ce, ee] = m(null), r = new URLSearchParams(
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
- ), Fe = () => i && i[0].type === "sort" && i[0].value || M || "", Te = () => {
62
+ ), Te = () => o && o[0].type === "sort" && o[0].value || M || "", Fe = () => {
63
63
  let e = {};
64
- return i && i[0].type === "filter" && (e[i[0].name] = i[0].value), o && (e = Object.assign({}, e, o)), e;
65
- }, [F, T] = m(Fe()), [Q, _] = m(Te()), te = $e(o);
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
- i?.map((s) => {
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 r.keys()) {
77
- i?.map((s) => {
76
+ for (const e of c.keys()) {
77
+ o?.map((s) => {
78
78
  s.name === e && (_({
79
- ...o,
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
- F,
88
+ T,
89
89
  Q,
90
90
  w,
91
91
  A,
92
92
  C,
93
93
  v
94
94
  ]), p(() => {
95
- g > 1 && (E(!0), se(g));
96
- }, [g]), p(() => {
97
- if (t.addElements && n in t.addElements && t.addElements[n].length > 0) {
98
- Ae(t.addElements[n]);
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[n], t.setAddElements(e);
100
+ delete e[a], t.setAddElements(e);
101
101
  }
102
102
  }, [t.addElements]), p(() => {
103
- if (t.updateElements && n in t.updateElements && t.updateElements[n].length > 0 && d.length > 0) {
104
- De(t.updateElements[n]);
105
- const e = { ...t.updateElements };
106
- delete e[n], t.setUpdateElements(e);
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 && n in t.removeElements && t.removeElements[n].length > 0 && d.length > 0) {
110
- Je(t.removeElements[n]);
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[n], t.setRemoveElements(e);
122
+ delete e[a], t.setRemoveElements(e);
113
123
  }
114
124
  }, [t.removeElements, d]);
115
125
  const _e = (e) => {
116
- e.type === "filter" ? (T(""), _({
117
- ...o,
126
+ e.type === "filter" ? (F(""), _({
127
+ ...m,
118
128
  [e.name]: e.value
119
- })) : (T(e.value), _(o ? { ...o } : {}));
129
+ })) : (F(e.value), _(m ? { ...m } : {}));
120
130
  }, xe = () => {
121
- typeof Z == "function" && Z() !== null || j(g + 1);
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 f = {
135
+ const i = {
126
136
  [oe]: e,
127
137
  [ie]: v,
128
- ...F && !w && { [me]: F },
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, 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
- }).catch((l) => {
142
- console.error(l), l?.response?.status !== 404 && be(!0), E(!1);
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 f = s;
162
+ let i = s;
153
163
  return e.forEach(
154
- (l) => f = f.map(
155
- (c) => c.id === l.id ? l : c
164
+ (n) => i = i.map(
165
+ (r) => r.id === n.id ? n : r
156
166
  )
157
- ), x(f, S || "id");
167
+ ), x(i, S || "id");
158
168
  });
159
169
  }, Je = (e) => {
160
- const s = e.map((l) => l.id), f = d.filter(
161
- (l) => s.indexOf(l.id) === -1
170
+ const s = e.map((n) => n.id), i = d.filter(
171
+ (n) => s.indexOf(n.id) === -1
162
172
  );
163
- y(x(f, S || "id"));
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__ */ u(
178
+ }, je = (e, s) => e !== void 0 ? /* @__PURE__ */ g(
169
179
  "li",
170
180
  {
171
- className: a.paginatedListItem,
181
+ className: l.paginatedListItem,
172
182
  "data-testid": "list-item",
173
183
  onClick: we,
174
- children: /* @__PURE__ */ u(Ie, { hideMessage: !0, children: We.cloneElement(fe, {
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__ */ u("li", { className: a.paginatedListItem, children: z }, e) : null;
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__ */ $("div", { className: a.listContainer, children: [
189
- /* @__PURE__ */ u(
198
+ return /* @__PURE__ */ U("div", { className: l.listContainer, children: [
199
+ /* @__PURE__ */ g(
190
200
  Pe,
191
201
  {
192
- title: Ee,
193
- subtitle: ge,
202
+ title: ge,
203
+ subtitle: Ee,
194
204
  showDebateConsultationSubtitle: he,
195
- sortOptions: i,
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__ */ u("div", { className: a.emptyListElement, children: G }) : /* @__PURE__ */ u("div", { className: a.emptyList, children: P || J.formatMessage({
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__ */ $(Qe, { children: [
211
- /* @__PURE__ */ $(
220
+ }) }) : /* @__PURE__ */ U(Qe, { children: [
221
+ /* @__PURE__ */ U(
212
222
  "ul",
213
223
  {
214
- className: Ue(a.paginatedList, {
215
- [a.paginatedListIsTablet]: !K && !L,
216
- [a.centeredList]: V === "column",
217
- [a.column]: V === "column",
218
- [a.twoElementsPerLine]: X === 2,
219
- [a.oneElementPerLine]: X === 1,
220
- [a.indexLayoutList]: pe,
221
- [a.listIsDesktop]: L,
222
- [a.listIsTablet]: Me && !L,
223
- [a.listIsMobile]: K
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__ */ u(
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: g,
249
+ currentPage: h,
240
250
  perPage: v,
241
251
  totalElements: Y || O,
242
252
  onLoad: xe,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logora/debate",
3
- "version": "0.3.117",
3
+ "version": "0.3.118",
4
4
  "type": "module",
5
5
  "license": "AGPL-3.0",
6
6
  "description": "Design system of @Logora made with React",