UNPKG

@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.

2 lines (1 loc) 3.13 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),m=require("react"),l=require("semantic-ui-react"),M=require("../connected-templates/PostIntro.js"),E=require("react-intl"),H=require("./utils.js"),W=require("./NoData.js"),C=require("react-redux"),L=require("../reducers/data-api.js"),V=require("react-router"),I=require("../../utils/data.js"),k=p=>{const{posts:i,numberOfColumns:f,sortFirstBy:n,countryCategory:o,postWidth:F,postHeight:P}=p,u=[];if(o&&n){const s=i.filter(c=>c[o].includes(Number(n))),y=i.filter(c=>!c[o].includes(Number(n)));u.push(...s,...y)}else u.push(...i);return e.jsx(l.Grid,{columns:f,children:e.jsx(l.GridRow,{children:u.map(s=>e.jsx(l.Grid.Column,{children:e.jsx("div",{style:{width:F,height:P,overflow:"hidden"},children:e.jsx(M.default,{style:{width:"100%",height:"100%",overflow:"hidden",margin:0,padding:0},as:l.Container,fluid:!0,post:s},s.id)})},s.id))})})},U=p=>{const{"data-group":i,"data-number-of-columns":f,"data-type":n,"data-taxonomy":o,"data-categories":F,"data-height":P,"data-post-width":u,"data-post-height":s,"data-number-of-items-per-page":y,"data-enable-sorting":c,"data-sort-first-by":T,"data-sorting-taxonomy":v}=p,A=C.useDispatch(),{locale:D}=V.useParams(),[N,x]=m.useState(!1),O=C.useSelector(t=>t),[h,w]=m.useState([]),R=I.toBoolean(c),j=O.getIn(["data","posts",i]),_=R&&T!=="none"?I.toNumber(T):null,a=j??{yearFilter:null,categoryFilter:null,countryFilter:null,page:1,countryTaxonomy:null,categoryTaxonomy:null},B=()=>{const t=a.yearFilter?H.getStartDateAndEndDateFromYear(Number(a.yearFilter)):null,d=a.countryFilter??null,g=a.categoryFilter??null,b=a.categoryTaxonomy||(o&&o!=="none"?o:null),r=a.countryTaxonomy||null;return{before:(t==null?void 0:t.endDate)||null,after:(t==null?void 0:t.startDate)||null,categoryFilter:g,categoryTaxonomy:b,countryFilter:d,countryTaxonomy:r}},G=async()=>{const t=B();if(!n){console.warn("FilteredPosts: missing post type. Configure 'type' in block settings."),w([]),x(!1);return}x(!0);const d=new Map;t.categoryTaxonomy&&t.categoryFilter!=null&&d.set(t.categoryTaxonomy,Array.isArray(t.categoryFilter)?t.categoryFilter:[t.categoryFilter]),t.countryTaxonomy&&t.countryFilter!=null&&d.set(t.countryTaxonomy,Array.isArray(t.countryFilter)?t.countryFilter:[t.countryFilter]),await L.getCustomPosts({after:t.after,before:t.before,perPage:Number(y||10),page:a.page||1,locale:D||"en",postType:n,taxonomy:void 0,category:void 0,taxonomyFilters:d}).then(g=>{if(g){const{data:b,meta:r}=g;w(b);const S=r&&r["x-wp-totalpages"]?r["x-wp-totalpages"]:1,q=r&&r["x-wp-total"]?r["x-wp-total"]:0;S&&q&&A({type:"SET_POSTS_PAGINATION",group:i,totalPages:Number(S),totalItems:Number(q)})}}).finally(()=>{x(!1)})};return m.useEffect(()=>{G()},[j,n,o,y]),e.jsx(l.Container,{fluid:!0,children:N?e.jsx(l.Loader,{active:!0,inline:"centered"}):!N&&h&&h.length>0?e.jsx(k,{posts:h,postWidth:Number(u),postHeight:Number(s),numberOfColumns:Number(f),sortFirstBy:_,countryCategory:v}):e.jsx(W.default,{noDataMsg:"No posts found"})})},Y=E.injectIntl(m.memo(U));exports.default=Y;