@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 6.79 kB
JavaScript
import{__decorate as i}from"tslib";import{action as s,computed as o,reaction as l}from"mobx";import{CACHE_DURATION as u,LANGUAGE_TYPE as a,MOBILE_BREAKPOINT as h}from"../../constants";import c from"../../data";import{SessionsSubButtonProvider as p}from"../providers/SessionsSubButtonProvider";import{SubButtonRegistry as d}from"../SubButtonRegistry";import{PREFIXES as S}from"./constants";import{SearchButtonsActions as y}from"./SearchButtonsActions";import{SearchButtonsFactory as B}from"./SearchButtonsFactory";import{SearchButtonsFilters as C}from"./SearchButtonsFilters";import{SearchButtonsState as g}from"./SearchButtonsState";import{countMapValues as b,extractPoiTypeId as P,isValidConfig as v}from"./utils";export default class e{constructor(t){this.poiTypeCountsCache=new Map,this.lastPoiTypeCountUpdate=0,this.rootStore=t,this.state=new g,this.filters=new C(t,this.state),this.actions=new y(t,this.state,this.filters),this.factory=new B(t,this.state,this.actions),this.setupReactions()}setupReactions(){l(()=>this.rootStore.boothStore.booths.length,()=>this.invalidatePoiTypeCounts())}get subButtonRegistry(){return this._subButtonRegistry||(this._subButtonRegistry=new d,this.registerSubButtonProviders()),this._subButtonRegistry}registerSubButtonProviders(){this.subButtonRegistry.register(new p(this.rootStore))}invalidatePoiTypeCounts(){this.poiTypeCountsCache.clear(),this.lastPoiTypeCountUpdate=0}get isVisible(){return this.state.isVisible}get shouldShow(){const{uiState:t}=this.rootStore;if(t.screenSize.width>=h)return this.state.isVisible;const r=!!(t.selectedExhibitor||t.selectedBooth||t.selectedEventItem||t.selectedRoute||t.menu||t.list.type===a);return this.state.isVisible&&!r}get activePoiFilterId(){return this.state.activePoiFilterId}get activeSubButtonsParentId(){return this.state.activeSubButtonsParentId}get activeSubButtonId(){return this.state.activeSubButtonId}get subButtonsEnabled(){return this.state.subButtonsEnabled}get searchShortcutState(){return this.state.searchShortcutState}get searchButtons(){const t=c.filterButtonsConfig;if(!v(t))return console.warn("[SearchButtonsStore] Invalid filterButtonsConfig detected"),[];const n=t.searchButtons;return this.factory.createButtons(n)}get hasAnySearchButtons(){return this.searchButtons.length>0}get hasActiveSearchButton(){return this.state.activePoiFilterId!==null||this.rootStore.uiState.selectedCategoryFilters.length>0}get activeSearchButtonLabel(){return this.state.activePoiFilterId?this.searchButtons.find(n=>n.id===this.state.activePoiFilterId)?.label||null:this.rootStore.uiState.selectedCategoryFilters.length>0?"Categories":null}get activeSubButtons(){return this.state.activeSubButtonsParentId?this.subButtonRegistry.getSubButtons(this.state.activeSubButtonsParentId):[]}get shouldShowSubButtons(){if(!this.state.subButtonsEnabled||!this.state.activeSubButtonsParentId)return!1;const t=this.searchButtons.find(n=>n.id===this.state.activeSubButtonsParentId);return!t||!t.active?!1:this.subButtonRegistry.shouldShowSubButtons(this.state.activeSubButtonsParentId)&&this.activeSubButtons.length>0}get hasActiveParentWithChildren(){return this.state.hasActiveParentWithChildren}get areAllSelected(){return this.filters.areAllSelected()}get activeChildrenCount(){return this.state.activeChildrenCount}get totalChildrenCount(){return this.filters.getChildrenCount()}get poiTypeCounts(){const t=Date.now();if(t-this.lastPoiTypeCountUpdate<u&&this.poiTypeCountsCache.size>0)return this.poiTypeCountsCache;const n=new Map;return this.rootStore.boothStore.booths.forEach(r=>{r.poiTypeId&&n.set(r.poiTypeId,(n.get(r.poiTypeId)||0)+1)}),this.poiTypeCountsCache=n,this.lastPoiTypeCountUpdate=t,n}get totalPoiTypeCount(){return b(this.poiTypeCounts)}get activePoiTypeId(){return this.state.activePoiFilterId?.startsWith(S.POI_TYPE)?P(this.state.activePoiFilterId):null}handleSearchButtonClick(t){this.actions.handleSearchButtonClick(t)}handleExtendedSearchButtonClick(t){this.actions.handleExtendedSearchButtonClick(t)}handleMainButtonClick(t){this.actions.handleMainButtonClick(t)}handleSessionsClick(){this.actions.handleSessionsClick()}togglePoiType(t){this.actions.togglePoiType(t)}clearAllFilters(){this.actions.clearAllFilters()}showSubButtons(t){this.actions.showSubButtons(t)}hideSubButtons(){this.actions.hideSubButtons()}handleSubButtonClick(t){this.state.activeSubButtonId!==t&&(this.state.setSubButton(t),this.state.activeSubButtonsParentId&&this.subButtonRegistry.handleSubButtonClick(this.state.activeSubButtonsParentId,t))}toggleChildFilter(t){this.filters.toggleChildFilter(t)}clearPoiTypeFilters(){this.filters.clearPoiTypeFilters()}clearAllChildFilters(){this.filters.clearAllChildFilters()}setActiveParentId(t){this.state.setActiveParentId(t)}showShortcuts(t){this.state.showShortcuts(t)}clearChildren(){this.state.clearChildren()}setSubButtonId(t){this.state.setSubButton(t)}setPoiFilterId(t){this.state.setPoiFilter(t)}getPoiTypeTotalCount(t){return this.poiTypeCounts.get(t)||0}isChildActive(t){return this.state.isChildActive(t)}getActiveParent(){return this.filters.getActiveParent()}}i([s],e.prototype,"invalidatePoiTypeCounts",null),i([o],e.prototype,"isVisible",null),i([o],e.prototype,"shouldShow",null),i([o],e.prototype,"activePoiFilterId",null),i([o],e.prototype,"activeSubButtonsParentId",null),i([o],e.prototype,"activeSubButtonId",null),i([o],e.prototype,"subButtonsEnabled",null),i([o],e.prototype,"searchShortcutState",null),i([o],e.prototype,"searchButtons",null),i([o],e.prototype,"hasAnySearchButtons",null),i([o],e.prototype,"hasActiveSearchButton",null),i([o],e.prototype,"activeSearchButtonLabel",null),i([o],e.prototype,"activeSubButtons",null),i([o],e.prototype,"shouldShowSubButtons",null),i([o],e.prototype,"hasActiveParentWithChildren",null),i([o],e.prototype,"areAllSelected",null),i([o],e.prototype,"activeChildrenCount",null),i([o],e.prototype,"totalChildrenCount",null),i([o],e.prototype,"poiTypeCounts",null),i([o],e.prototype,"totalPoiTypeCount",null),i([o],e.prototype,"activePoiTypeId",null),i([s],e.prototype,"handleSearchButtonClick",null),i([s],e.prototype,"handleExtendedSearchButtonClick",null),i([s],e.prototype,"handleMainButtonClick",null),i([s],e.prototype,"handleSessionsClick",null),i([s],e.prototype,"togglePoiType",null),i([s],e.prototype,"clearAllFilters",null),i([s],e.prototype,"showSubButtons",null),i([s],e.prototype,"hideSubButtons",null),i([s],e.prototype,"handleSubButtonClick",null),i([s],e.prototype,"toggleChildFilter",null),i([s],e.prototype,"clearPoiTypeFilters",null),i([s],e.prototype,"clearAllChildFilters",null),i([s],e.prototype,"setActiveParentId",null),i([s],e.prototype,"showShortcuts",null),i([s],e.prototype,"clearChildren",null),i([s],e.prototype,"setSubButtonId",null),i([s],e.prototype,"setPoiFilterId",null);