UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 3.37 kB
import{__decorate as o}from"tslib";import{action as m,computed as i,observable as u}from"mobx";import{generateUniqueSlug as k}from"../tools/slug";export default class n{constructor(t){this.eventItems=[],this.rootStore=t}findByNameOrSlug(t){return this.eventItems.find(e=>e.name===t||e.slug===t||e.externalId===t)}get bookmarked(){return this.eventItems.filter(t=>t.bookmarked)}get visited(){return this.eventItems.filter(t=>t.visited)}get tracks(){const t=new Map;return this.eventItems.forEach(e=>{e.tracks.forEach(r=>{t.set(r.id,r)})}),Array.from(t.values()).sort((e,r)=>e.name.localeCompare(r.name))}getEventsByTrack(t){return this.eventItems.filter(e=>e.tracks.some(r=>r.id===t))}getEventsBySpeaker(t){return this.eventItems.filter(e=>e.speakers.some(r=>r.id===t))}get venues(){const t=new Map;return this.eventItems.forEach(e=>{if(e.boothId){const r=this.rootStore.boothStore.booths.find(a=>a.id===e.boothId);r&&t.set(r.id,r)}}),Array.from(t.values()).sort((e,r)=>e.name.localeCompare(r.name))}getEventsByVenue(t){return this.eventItems.filter(e=>e.boothId===t)}get pastEvents(){const t=new Date;return this.eventItems.filter(e=>new Date(e.endDate)<t)}get futureEvents(){const t=new Date;return this.eventItems.filter(e=>new Date(e.startDate)>t)}get liveEvents(){const t=new Date;return this.eventItems.filter(e=>{const r=new Date(e.startDate),a=new Date(e.endDate);return r<=t&&t<=a})}get todayEvents(){const t=new Date;return t.setHours(0,0,0,0),this.eventItems.filter(e=>{const r=new Date(e.startDate);return r.setHours(0,0,0,0),r.getTime()===t.getTime()})}get tomorrowEvents(){const t=new Date;return t.setDate(t.getDate()+1),t.setHours(0,0,0,0),this.eventItems.filter(e=>{const r=new Date(e.startDate);return r.setHours(0,0,0,0),r.getTime()===t.getTime()})}replaceBookmarked(t){const e=(t||[]).map(s=>this.eventItems.find(l=>l.id===s)).filter(s=>s),r=new Set(e),a=this.bookmarked.filter(s=>!r.has(s));for(const s of a)s.bookmarked=!1;for(const s of e)s.bookmarked=!0}replaceVisited(t){const e=(t||[]).map(s=>this.eventItems.find(l=>l.id===s)).filter(s=>s),r=new Set(e),a=this.visited.filter(s=>!r.has(s));for(const s of a)s.visited=!1;for(const s of e)s.visited=!0}}o([i],n.prototype,"bookmarked",null),o([i],n.prototype,"visited",null),o([i],n.prototype,"tracks",null),o([i],n.prototype,"venues",null),o([i],n.prototype,"pastEvents",null),o([i],n.prototype,"futureEvents",null),o([i],n.prototype,"liveEvents",null),o([i],n.prototype,"todayEvents",null),o([i],n.prototype,"tomorrowEvents",null),o([m],n.prototype,"replaceBookmarked",null),o([m],n.prototype,"replaceVisited",null);export class EventItem{constructor(t,e,r,a,s,l,p,d,v=[],c=[],f={type:"event"}){this.id=t,this.externalId=e,this.boothId=r,this.name=a,this.description=s,this.startDate=l,this.endDate=p,this.logoFile=d,this.speakers=v,this.tracks=c,this.entity=f,this.bookmarked=!1,this.visited=!1,this.slug=k(a||`event-${t}`)}get isEnded(){return this.endDate&&new Date(this.endDate).getTime()<new Date().getTime()}get hasSpeakers(){return this.speakers.length>0}get hasTracks(){return this.tracks.length>0}get primaryTrack(){return this.tracks.length>0?this.tracks[0]:null}get speakerNames(){return this.speakers.map(t=>t.name).join(", ")}get trackNames(){return this.tracks.map(t=>t.name).join(", ")}}o([u],EventItem.prototype,"bookmarked",void 0),o([u],EventItem.prototype,"visited",void 0);