UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 3.64 kB
import{jsx as n,jsxs as i,Fragment as H}from"react/jsx-runtime";import"./Schedule.scss";import D from"classnames";import h from"dateformat";import{observer as I}from"mobx-react-lite";import{useEffect as B,useState as C}from"react";import v from"../store";import{t as G}from"../utils/i18n";import O from"../utils/sanitizeHtml";import{EventBadge as A,ShowMoreButton as z}from"./";function W(l,d){const m=new Date;return l<=m&&m<=d}function q(l){const d=new Date;return new Date(l)<d}const J=I(({events:l=[],descriptionMaxLength:d=200,showBooths:m=!1,isSessions:_=!1,onEventClick:p})=>{const[k,w]=C({}),g=new Date,S=l.filter(e=>(e.endDate?new Date(e.endDate):new Date(e.startDate))>g),j=l.filter(e=>(e.endDate?new Date(e.endDate):new Date(e.startDate))<=g),f=S.reduce((e,t)=>{const[s]=t.startDate.split("T");return e[s]?e[s].push(t):e[s]=[t],e},{}),u=j.reduce((e,t)=>{const[s]=t.startDate.split("T");return e[s]?e[s].push(t):e[s]=[t],e},{});B(()=>{const e={};for(const t in f)e[t]=f[t].map(()=>({showFullDescription:!1}));for(const t in u)e[t]=u[t].map(()=>({showFullDescription:!1}));w(e)},[l.map(e=>e.id).join(",")]);const E=(e,t,s)=>{e.preventDefault(),e.stopPropagation(),w(a=>{const o={...a};return Array.isArray(o[t])||(o[t]=[]),o[t][s]||(o[t][s]={showFullDescription:!1}),o[t][s].showFullDescription=!o[t][s].showFullDescription,o})},P=(e,t)=>e.length>d&&!t?e.slice(0,d)+"...":e,F=e=>{const t=v.sessionsFilterStore.state.filters.use24hFormat.value,s=new Date(e);return h(s,t?"HH:MM":"h:MMtt")},$=e=>{const[t,s,a]=e.split("-"),o=new Date(parseInt(t),parseInt(s)-1,parseInt(a));return{day:a,month:h(o,"mmm"),weekday:h(o,"ddd"),full:h(o,"dddd, mmmm d")}},M=({children:e,link:t,current:s,ended:a,event:o})=>{const r=c=>{p&&(c.preventDefault(),p(o))};return t?n("a",{href:t,className:D("efp-schedule__event",s,a),target:"_blank",rel:"noopener noreferrer",onClick:r,children:e}):n("div",{className:D("efp-schedule__event",{ended:a}),onClick:r,children:e})},y=(e,t=!1)=>Object.entries(e).map(([s,a])=>{const o=$(s);return i("div",{className:"efp-schedule__item",children:[n("div",{className:"efp-schedule__date","aria-label":`Date: ${o.full}`,children:i("div",{className:"efp-schedule__date-sticky",children:[n("div",{children:o.day}),n("div",{children:o.month}),n("div",{children:o.weekday})]})}),n("div",{className:"efp-schedule__events",role:"list",children:a.map((r,c)=>{const N=r.boothId?v.boothStore.boothById.get(Number(r.boothId)):null,b=k[s]?.[c]?.showFullDescription??!1;return n("div",{role:"listitem","data-event-id":r.id,onClick:()=>p?.(r),style:{cursor:p?"pointer":"default"},children:i(M,{link:"",ended:r.isEnded||q(r.endDate||r.startDate),current:W(r.startDate,r.endDate),event:r,children:[i("span",{children:[F(r.startDate),r.endDate?` - ${F(r.endDate)}`:null]}),i("strong",{children:[r.name,n(A,{event:r})]}),n("div",{className:"efp-schedule__event-booth-and-tracks",children:N&&m&&n("div",{className:"efp-schedule__event-booth",children:n("div",{children:N.name})})}),r.logoFile&&n("div",{className:"efp-schedule__event-logo",children:n("img",{src:r.logoFile,alt:r.name,crossOrigin:"anonymous"})}),r.description&&!_&&i("div",{className:"efp-schedule__event-desc",children:[n("div",{id:`event-desc-${s}-${c}`,dangerouslySetInnerHTML:{__html:O(P(r.description,b))}}),r.description.length>d&&n(z,{expanded:b,onClick:T=>E(T,s,c),"aria-controls":`event-desc-${s}-${c}`})]})]})},r.id)})})]},s)});return i("div",{className:D("efp-schedule",{"is-sessions":_}),children:[y(f),Object.keys(u).length>0&&i(H,{children:[n("div",{className:"efp-schedule__past-events-header",children:G("Past Sessions")}),y(u,!0)]})]})});export default J;