@devgateway/dvz-ui-react
Version:
A modular, embeddable React component library for data visualization and UI, built with TypeScript. Provides reusable components for charts, maps, dashboards, and more, with built-in support for internationalization and Redux integration.
124 lines (123 loc) • 4.34 kB
JavaScript
import { jsx as o } from "react/jsx-runtime";
import R, { useState as S, useEffect as W } from "react";
import { Container as A, Loader as j, Grid as I, GridRow as L } from "semantic-ui-react";
import M from "../connected-templates/PostIntro.js";
import { injectIntl as V } from "react-intl";
import { getStartDateAndEndDateFromYear as k } from "./utils.js";
import Y from "./NoData.js";
import { useDispatch as q, useSelector as z } from "react-redux";
import { getCustomPosts as J } from "../reducers/data-api.js";
import { useParams as K } from "react-router";
import { toNumber as Q, toBoolean as U } from "../../utils/data.js";
const X = (d) => {
const { posts: i, numberOfColumns: g, sortFirstBy: n, countryCategory: e, postWidth: b, postHeight: x } = d, l = [];
if (e && n) {
const a = i.filter((c) => c[e].includes(Number(n))), m = i.filter((c) => !c[e].includes(Number(n)));
l.push(...a, ...m);
} else
l.push(...i);
return /* @__PURE__ */ o(I, { columns: g, children: /* @__PURE__ */ o(L, { children: l.map((a) => /* @__PURE__ */ o(I.Column, { children: /* @__PURE__ */ o("div", { style: { width: b, height: x, overflow: "hidden" }, children: /* @__PURE__ */ o(
M,
{
style: {
width: "100%",
height: "100%",
overflow: "hidden",
margin: 0,
padding: 0
},
as: A,
fluid: !0,
post: a
},
a.id
) }) }, a.id)) }) });
}, Z = (d) => {
const {
"data-group": i,
"data-number-of-columns": g,
"data-type": n,
"data-taxonomy": e,
"data-categories": b,
"data-height": x,
"data-post-width": l,
"data-post-height": a,
"data-number-of-items-per-page": m,
"data-enable-sorting": c,
"data-sort-first-by": F,
"data-sorting-taxonomy": D
} = d, v = q(), { locale: O } = K(), [P, p] = S(!1), B = z((t) => t), [f, T] = S([]), G = U(c), N = B.getIn(["data", "posts", i]), _ = G && F !== "none" ? Q(F) : null, s = N ?? {
yearFilter: null,
categoryFilter: null,
countryFilter: null,
page: 1,
countryTaxonomy: null,
categoryTaxonomy: null
}, E = () => {
const t = s.yearFilter ? k(Number(s.yearFilter)) : null, u = s.countryFilter ?? null, y = s.categoryFilter ?? null, h = s.categoryTaxonomy || (e && e !== "none" ? e : null), r = s.countryTaxonomy || null;
return {
before: (t == null ? void 0 : t.endDate) || null,
after: (t == null ? void 0 : t.startDate) || null,
categoryFilter: y,
categoryTaxonomy: h,
countryFilter: u,
countryTaxonomy: r
};
}, H = async () => {
const t = E();
if (!n) {
console.warn("FilteredPosts: missing post type. Configure 'type' in block settings."), T([]), p(!1);
return;
}
p(!0);
const u = /* @__PURE__ */ new Map();
t.categoryTaxonomy && t.categoryFilter != null && u.set(
t.categoryTaxonomy,
Array.isArray(t.categoryFilter) ? t.categoryFilter : [t.categoryFilter]
), t.countryTaxonomy && t.countryFilter != null && u.set(
t.countryTaxonomy,
Array.isArray(t.countryFilter) ? t.countryFilter : [t.countryFilter]
), await J({
after: t.after,
before: t.before,
perPage: Number(m || 10),
page: s.page || 1,
locale: O || "en",
postType: n,
// explicit undefineds for legacy params to satisfy types
taxonomy: void 0,
category: void 0,
taxonomyFilters: u
}).then((y) => {
if (y) {
const { data: h, meta: r } = y;
T(h);
const w = r && r["x-wp-totalpages"] ? r["x-wp-totalpages"] : 1, C = r && r["x-wp-total"] ? r["x-wp-total"] : 0;
w && C && v({
type: "SET_POSTS_PAGINATION",
group: i,
totalPages: Number(w),
totalItems: Number(C)
});
}
}).finally(() => {
p(!1);
});
};
return W(() => {
H();
}, [N, n, e, m]), /* @__PURE__ */ o(A, { fluid: !0, children: P ? /* @__PURE__ */ o(j, { active: !0, inline: "centered" }) : !P && f && f.length > 0 ? /* @__PURE__ */ o(
X,
{
posts: f,
postWidth: Number(l),
postHeight: Number(a),
numberOfColumns: Number(g),
sortFirstBy: _,
countryCategory: D
}
) : /* @__PURE__ */ o(Y, { noDataMsg: "No posts found" }) });
}, ut = V(R.memo(Z));
export {
ut as default
};