@logora/debate 0.3.47 → 0.3.48

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,7 +1,7 @@
1
- import { jsxs as U, jsx as d, Fragment as Le } from "react/jsx-runtime";
1
+ import { jsxs as U, jsx as c, Fragment as Le } from "react/jsx-runtime";
2
2
  import je from "@rooks/use-previous";
3
3
  import Be from "classnames";
4
- import Qe, { useState as m, useEffect as g } from "react";
4
+ import Qe, { useState as m, useEffect as h } from "react";
5
5
  import { useIntl as Ue } from "react-intl";
6
6
  import { useLocation as We } from "react-router";
7
7
  import a from "./PaginatedList.module.scss.js";
@@ -23,7 +23,7 @@ const rt = ({
23
23
  resource: _,
24
24
  currentListId: n,
25
25
  withToken: ae,
26
- perPage: h,
26
+ perPage: p,
27
27
  perPageParam: le = "per_page",
28
28
  pageParam: ie = "page",
29
29
  sortParam: oe = "sort",
@@ -33,7 +33,7 @@ const rt = ({
33
33
  onUpdateTotal: W,
34
34
  onElementsLoad: R,
35
35
  transformData: z,
36
- uniqueIdKey: p = "id",
36
+ uniqueIdKey: v = "id",
37
37
  children: de,
38
38
  resourcePropName: fe,
39
39
  loadingComponent: G,
@@ -52,17 +52,17 @@ const rt = ({
52
52
  withUrlParams: Se = !1,
53
53
  onLoadNewPage: $
54
54
  }) => {
55
- const J = Ue(), t = Ge(), H = Pe(), I = We(), { isMobile: K, isTablet: ye, isDesktop: L } = Ve(), [b, f] = m(!1), [we, Ne] = m(!1), [v, S] = Xe(n, []), [O, Me] = m(
56
- v?.length || 0
57
- ), [c, j] = m(M || 1), [y, B] = m(w || null), [k, q] = m(null), [Re, ee] = m(null), r = new URLSearchParams(
55
+ const J = Ue(), t = Ge(), H = Pe(), I = We(), { isMobile: K, isTablet: ye, isDesktop: L } = Ve(), [b, u] = m(!1), [we, Ne] = m(!1), [k, S] = Xe(n, []), [O, Me] = m(
56
+ k?.length || 0
57
+ ), [E, j] = m(M || 1), [y, B] = m(w || null), [C, q] = m(null), [Re, ee] = m(null), r = new URLSearchParams(
58
58
  typeof window < "u" ? window.location.search : I.search
59
59
  ), be = () => i && i[0].type === "sort" && i[0].value || N || "", ke = () => {
60
60
  let e = {};
61
61
  return i && i[0].type === "filter" && (e[i[0].name] = i[0].value), o && (e = Object.assign({}, e, o)), e;
62
- }, [C, F] = m(be()), [Q, T] = m(ke()), te = je(o);
63
- M && M !== c && j(M), w !== void 0 && w !== y && B(w), N !== void 0 && N !== C && F(N), te && JSON.stringify(o) !== JSON.stringify(te) && JSON.stringify(o) !== JSON.stringify(Q) && T(o), g(() => {
62
+ }, [F, T] = m(be()), [Q, x] = m(ke()), te = je(o);
63
+ M && M !== E && j(M), w !== void 0 && w !== y && B(w), N !== void 0 && N !== F && T(N), te && JSON.stringify(o) !== JSON.stringify(te) && JSON.stringify(o) !== JSON.stringify(Q) && x(o), h(() => {
64
64
  if (r.get("tagId") && q(Number.parseInt(r.get("tagId"))), r.get("search") && B(r.get("search")), r.get("sort")) {
65
- F(r.get("sort"));
65
+ T(r.get("sort"));
66
66
  for (const e of r.values()) {
67
67
  i?.map((s) => {
68
68
  s.value === e && ee(s.name);
@@ -72,37 +72,37 @@ const rt = ({
72
72
  }
73
73
  for (const e of r.keys()) {
74
74
  i?.map((s) => {
75
- s.name === e && (T({
75
+ s.name === e && (x({
76
76
  ...o,
77
77
  [s.name]: s.value
78
78
  }), ee(s.name));
79
79
  });
80
80
  break;
81
81
  }
82
- }, [I.search]), g(() => {
83
- _ ? (j(1), S([]), f(!0), se(1)) : f(!1);
82
+ }, [I.search]), h(() => {
83
+ _ ? (j(1), S([]), u(!0), se(1)) : u(!1);
84
84
  }, [
85
- C,
85
+ F,
86
86
  Q,
87
87
  y,
88
88
  _,
89
- k,
90
- h
91
- ]), g(() => {
92
- c > 1 && (f(!0), se(c));
93
- }, [c]), g(() => {
89
+ C,
90
+ p
91
+ ]), h(() => {
92
+ E > 1 && (u(!0), se(E));
93
+ }, [E]), h(() => {
94
94
  if (t.addElements && n in t.addElements && t.addElements[n].length > 0) {
95
95
  Te(t.addElements[n]);
96
96
  const e = t.addElements;
97
97
  delete e[n], t.setAddElements(e);
98
98
  }
99
- }, [t.addElements]), g(() => {
99
+ }, [t.addElements]), h(() => {
100
100
  if (t.updateElements && n in t.updateElements && t.updateElements[n].length > 0) {
101
101
  xe(t.updateElements[n]);
102
102
  const e = t.updateElements;
103
103
  delete e[n], t.setUpdateElements(e);
104
104
  }
105
- }, [t.updateElements]), g(() => {
105
+ }, [t.updateElements]), h(() => {
106
106
  if (t.removeElements && n in t.removeElements && t.removeElements[n].length > 0) {
107
107
  Ae(t.removeElements[n]);
108
108
  const e = t.removeElements;
@@ -110,69 +110,71 @@ const rt = ({
110
110
  }
111
111
  }, [t.removeElements]);
112
112
  const Ce = (e) => {
113
- e.type === "filter" ? (F(""), T({
113
+ e.type === "filter" ? (T(""), x({
114
114
  ...o,
115
115
  [e.name]: e.value
116
- })) : (F(e.value), T(o ? { ...o } : {}));
116
+ })) : (T(e.value), x(o ? { ...o } : {}));
117
117
  }, Fe = () => {
118
- typeof $ == "function" && $() !== null || j(c + 1);
118
+ typeof $ == "function" && $() !== null || j(E + 1);
119
119
  }, se = (e) => {
120
120
  const s = ae ? H.getListWithToken : H.getList;
121
- if ((e - 1) * h <= (Z || O) || e === 1) {
122
- const u = {
121
+ if ((e - 1) * p <= (Z || O) || e === 1) {
122
+ const d = {
123
123
  [ie]: e,
124
- [le]: h,
125
- ...C && !y && { [oe]: C },
124
+ [le]: p,
125
+ ...F && !y && { [oe]: F },
126
126
  ...y && { [me]: y },
127
127
  ...pe === !0 && { countless: !0 },
128
128
  ...Q,
129
- ...k && { [re]: k }
129
+ ...C && { [re]: C }
130
130
  };
131
- s(_, u).then((l) => {
132
- const x = l.headers;
133
- x && D in x && (Me(
134
- Number.parseInt(x[D || "total"], 10)
135
- ), W && W(x[D || "total"]));
136
- let E = l?.data?.data;
137
- R && R(E), z && (E = E.filter(z)), t.addElements && n in t.addElements && t.addElements[n].length > 0 && (E = [...t.addElements[n], E]), _e(E), f(!1);
131
+ s(_, d).then((l) => {
132
+ const f = l.headers;
133
+ f && D in f && (Me(
134
+ Number.parseInt(f[D || "total"], 10)
135
+ ), W && W(f[D || "total"]));
136
+ let g = l?.data?.data;
137
+ R && R(g), z && (g = g.filter(z)), t.addElements && n in t.addElements && t.addElements[n].length > 0 && (g = [...t.addElements[n], g]), _e(g), u(!1);
138
138
  }).catch((l) => {
139
- console.error(l), l?.response?.status !== 404 && Ne(!0), f(!1);
139
+ console.error(l), l?.response?.status !== 404 && Ne(!0), u(!1);
140
140
  });
141
141
  } else
142
- f(!1);
142
+ u(!1);
143
143
  }, Te = (e) => {
144
144
  S(
145
- (s) => A([...e, ...s], p || "id")
145
+ (s) => A([...e, ...s], v || "id")
146
146
  ), R && R(e);
147
147
  }, xe = (e) => {
148
- let s = v;
149
- e.forEach(
150
- (u) => s = s.map(
151
- (l) => l.id === u.id ? u : l
152
- )
153
- ), S(A(s, p || "id"));
148
+ S((s) => {
149
+ let d = s;
150
+ return e.forEach(
151
+ (l) => d = d.map(
152
+ (f) => f.id === l.id ? l : f
153
+ )
154
+ ), A(d, v || "id");
155
+ });
154
156
  }, Ae = (e) => {
155
- const s = e.map((l) => l.id), u = v.filter(
157
+ const s = e.map((l) => l.id), d = k.filter(
156
158
  (l) => s.indexOf(l.id) === -1
157
159
  );
158
- S(A(u, p || "id"));
160
+ S(A(d, v || "id"));
159
161
  }, _e = (e) => {
160
162
  S(
161
- (s) => A([...s, ...e], p || "id")
163
+ (s) => A([...s, ...e], v || "id")
162
164
  );
163
- }, De = (e, s) => e !== void 0 ? /* @__PURE__ */ d(
165
+ }, De = (e, s) => e !== void 0 ? /* @__PURE__ */ c(
164
166
  "li",
165
167
  {
166
168
  className: a.paginatedListItem,
167
169
  "data-testid": "list-item",
168
170
  onClick: ve,
169
- children: /* @__PURE__ */ d(Ze, { hideMessage: !0, children: Qe.cloneElement(de, {
171
+ children: /* @__PURE__ */ c(Ze, { hideMessage: !0, children: Qe.cloneElement(de, {
170
172
  index: s,
171
173
  [fe]: e
172
174
  }) })
173
175
  },
174
- e[p || "id"]
175
- ) : null, Je = (e) => G ? /* @__PURE__ */ d("li", { className: a.paginatedListItem, children: G }, e) : null;
176
+ e[v || "id"]
177
+ ) : null, Je = (e) => G ? /* @__PURE__ */ c("li", { className: a.paginatedListItem, children: G }, e) : null;
176
178
  if (we)
177
179
  throw new Error(
178
180
  J.formatMessage({
@@ -181,7 +183,7 @@ const rt = ({
181
183
  })
182
184
  );
183
185
  return /* @__PURE__ */ U("div", { className: a.listContainer, children: [
184
- /* @__PURE__ */ d(
186
+ /* @__PURE__ */ c(
185
187
  ze,
186
188
  {
187
189
  title: ue,
@@ -189,14 +191,14 @@ const rt = ({
189
191
  defaultSelectOption: Re,
190
192
  searchBar: ce,
191
193
  tagList: ne,
192
- activeTagId: k,
194
+ activeTagId: C,
193
195
  onSearch: (e) => B(e),
194
196
  onSortChange: Ce,
195
197
  onTagChange: (e) => q(e),
196
198
  withUrlParams: Se
197
199
  }
198
200
  ),
199
- !b && v.length === 0 ? P ? /* @__PURE__ */ d("div", { className: a.emptyListElement, children: P }) : /* @__PURE__ */ d("div", { className: a.emptyList, children: V || J.formatMessage({
201
+ !b && k.length === 0 ? P ? /* @__PURE__ */ c("div", { className: a.emptyListElement, children: P }) : /* @__PURE__ */ c("div", { className: a.emptyList, children: V || J.formatMessage({
200
202
  id: "info.emptyList",
201
203
  defaultMessage: "No items for now."
202
204
  }) }) : /* @__PURE__ */ U(Le, { children: [
@@ -216,20 +218,20 @@ const rt = ({
216
218
  }),
217
219
  style: { gap: ge },
218
220
  children: [
219
- v.map(De),
220
- b ? Array(h).fill().map((e, s) => s).map(Je) : null
221
+ k.map(De),
222
+ b ? Array(p).fill().map((e, s) => s).map(Je) : null
221
223
  ]
222
224
  }
223
225
  ),
224
- !b && he !== !1 && /* @__PURE__ */ d(
226
+ !b && he !== !1 && /* @__PURE__ */ c(
225
227
  Ye,
226
228
  {
227
229
  buttonText: J.formatMessage({
228
230
  id: "action.see_more",
229
231
  defaultMessage: "See more"
230
232
  }),
231
- currentPage: c,
232
- perPage: h,
233
+ currentPage: E,
234
+ perPage: p,
233
235
  totalElements: Z || O,
234
236
  onLoad: Fe,
235
237
  isLoading: b,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logora/debate",
3
- "version": "0.3.47",
3
+ "version": "0.3.48",
4
4
  "type": "module",
5
5
  "license": "AGPL-3.0",
6
6
  "description": "Design system of @Logora made with React",