UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 2.56 kB
import{__decorate as o}from"tslib";import{action as l,computed as a,observable as n}from"mobx";import{generateUniqueSlug as c}from"../tools/slug";export class SpeakerItem{constructor(e,t,i,p,r,u,m={type:"speaker"}){this.id=e,this.externalId=t,this.name=i,this.company=p,this.jobTitle=r,this.photoFile=u,this.entity=m,this.bookmarked=!1,this.slug=c(i||`speaker-${e}`)}get displayName(){return this.name}get fullTitle(){const e=[this.name];return this.jobTitle&&e.push(this.jobTitle),this.company&&e.push(this.company),e.join(" - ")}get hasPhoto(){return!!this.photoFile}get hasCompany(){return!!this.company}get hasJobTitle(){return!!this.jobTitle}}o([n],SpeakerItem.prototype,"bookmarked",void 0);export default class s{constructor(e){this.speakersMap=new Map,this.selectedSpeaker=null,this.rootStore=e}get speakers(){return Array.from(this.speakersMap.values()).sort((e,t)=>e.name.localeCompare(t.name))}getSpeakerById(e){return this.speakersMap.get(e)}getSpeakerBySlug(e){return Array.from(this.speakersMap.values()).find(t=>t.slug===e)}addSpeaker(e){if(this.speakersMap.has(e.id))return this.speakersMap.get(e.id);const t=new SpeakerItem(e.id,e.externalId,e.name,e.company,e.jobTitle,e.photoFile);return this.speakersMap.set(e.id,t),t}get companies(){const e=new Set;return this.speakers.forEach(t=>{t.company&&e.add(t.company)}),Array.from(e).sort()}get jobTitles(){const e=new Set;return this.speakers.forEach(t=>{t.jobTitle&&e.add(t.jobTitle)}),Array.from(e).sort()}getSpeakersByCompany(e){return this.speakers.filter(t=>t.company===e)}getSpeakersByJobTitle(e){return this.speakers.filter(t=>t.jobTitle===e)}getEventsBySpeaker(e){return this.rootStore.eventStore.eventItems.filter(t=>t.speakers.some(i=>i.id===e))}findBySlug(e){return this.getSpeakerBySlug(e)}selectSpeaker(e,t=!0){this.selectedSpeaker=e,this.rootStore.uiState.details=e,this.rootStore.uiState.desiredOverlaySize="medium"}get bookmarked(){return this.speakers.filter(e=>e.bookmarked)}replaceBookmarked(e){const t=(e||[]).map(r=>this.speakersMap.get(r)).filter(r=>r),i=new Set(t),p=this.bookmarked.filter(r=>!i.has(r));for(const r of p)r.bookmarked=!1;for(const r of t)r.bookmarked=!0}clearSelectedSpeaker(){this.selectedSpeaker=null,this.rootStore.uiState.details=null}}o([n],s.prototype,"selectedSpeaker",void 0),o([a],s.prototype,"speakers",null),o([a],s.prototype,"companies",null),o([a],s.prototype,"jobTitles",null),o([l],s.prototype,"selectSpeaker",null),o([a],s.prototype,"bookmarked",null),o([l],s.prototype,"replaceBookmarked",null),o([l],s.prototype,"clearSelectedSpeaker",null);