UNPKG

mapwize-ui-react-native

Version:

Fully featured and ready to use UI to add Mapwize Indoor Maps and Navigation in your React Native app.

1,167 lines (1,019 loc) 55.3 kB
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import produce from 'immer'; import { buildDirectionError, buildDirectionInfo, buildFloorDisplays, buildLanguageDisplay, buildLanguageDisplays, buildNavigationInfo, buildPlaceDetails, buildPlacelistDetails, buildSearchResult, titleForLanguage } from './formatter'; import { lang_available_locale, lang_back, lang_change_language, lang_change_universe, lang_choose_destination, lang_choose_starting_point, lang_coordinates, lang_current_location, lang_destination, lang_direction, lang_entering_venue, lang_floor_controller, lang_search_global, lang_search_no_results, lang_search_venue, lang_start } from './localizor'; import { DirectionOptions, NavigationProp } from 'mapwize-sdk-react-native'; export class UIControllerStore { constructor(defaultState, render, mapActionsDispatcher, apiService, devCallbackInterceptor) { _defineProperty(this, "render", void 0); _defineProperty(this, "state", void 0); _defineProperty(this, "mapActionsDispatcher", void 0); _defineProperty(this, "devCallbackInterceptor", void 0); _defineProperty(this, "apiService", void 0); this.render = render; this.state = defaultState; this.mapActionsDispatcher = mapActionsDispatcher; this.apiService = apiService; this.devCallbackInterceptor = devCallbackInterceptor; } getLocale() { return lang_available_locale().find(l => l.code === this.state.uiControllerState.preferredLanguage); } getAvailableLocales() { return lang_available_locale(); } async setLocale(locale) { if (!lang_available_locale().map(l => l.code).includes(locale)) { return; } const nextState = await produce(this.state, async draftState => { draftState.uiControllerState.preferredLanguage = locale; draftState.universeSelectorState.tooltipMessage = lang_change_universe(locale); draftState.languageSelectorState.tooltipMessage = lang_change_language(locale); draftState.floorControllerState.tooltipMessage = lang_floor_controller(locale); draftState.searchBarState.backTooltipMessage = lang_back(locale); draftState.searchBarState.directionTooltipMessage = lang_direction(locale); draftState.searchResultListState.noResultLabel = lang_search_no_results(locale); if (this.state.uiControllerState.venue) { draftState.searchBarState.searchPlaceholder = lang_search_venue(locale, titleForLanguage(this.state.uiControllerState.venue, locale)); } else { draftState.searchBarState.searchPlaceholder = lang_search_global(locale); } draftState.searchDirectionBarState.fromPlaceholder = lang_choose_starting_point(locale); draftState.searchDirectionBarState.toPlaceholder = lang_choose_destination(locale); if (this.state.uiControllerState.directionFromPoint) { if (this.state.uiControllerState.directionFromPoint.objectClass === 'Place') { draftState.searchDirectionBarState.fromQuery = titleForLanguage(this.state.uiControllerState.directionFromPoint, locale); } else { draftState.searchDirectionBarState.fromQuery = lang_coordinates(locale); } } if (this.state.uiControllerState.directionToPoint) { if (this.state.uiControllerState.directionToPoint.objectClass === 'Place' || this.state.uiControllerState.directionToPoint.objectClass === 'Placelist') { draftState.searchDirectionBarState.toQuery = titleForLanguage(this.state.uiControllerState.directionToPoint, locale); } else { draftState.searchDirectionBarState.toQuery = lang_coordinates(locale); } } draftState.bottomViewState.language = locale; if (this.state.uiControllerState.selectedContent) { if (this.state.uiControllerState.selectedContent.objectClass === 'Place' || this.state.uiControllerState.selectedContent.objectClass === 'PlaceDetails') { const details = await this.apiService.getPlaceDetailsWithId(this.state.uiControllerState.selectedContent._id); draftState.bottomViewState.content = buildPlaceDetails(details, locale); } if (this.state.uiControllerState.selectedContent.objectClass === 'Placelist') { const places = await this.apiService.getPlacesForPlacelist(this.state.uiControllerState.selectedContent); draftState.bottomViewState.content = buildPlacelistDetails(this.state.uiControllerState.selectedContent, places, locale); } } }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.mapActionsDispatcher.setLanguage(locale); } setUnit(unit) { const nextState = produce(this.state, draftState => { draftState.uiControllerState.unit = unit; if (this.state.uiControllerState.direction) { draftState.bottomViewState.directionContent = buildDirectionInfo(this.state.uiControllerState.direction, unit); } }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } getUnit() { return this.state.uiControllerState.unit; } getUnits() { return ['m', 'ft']; } setLanguage(language) { const nextState = produce(this.state, draftState => { draftState.uiControllerState.language = language; draftState.universeSelectorState.tooltipMessage = lang_change_universe(language); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } toggleUniverseSelector() { const nextState = produce(this.state, draftState => { draftState.universeSelectorState.isExpanded = !this.state.universeSelectorState.isExpanded; draftState.languageSelectorState.isExpanded = false; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } changeSelectedUniverse(universe) { const nextState = produce(this.state, draftState => { draftState.universeSelectorState.isExpanded = false; draftState.universeSelectorState.selectedUniverse = universe; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } toggleLanguageSelector() { const nextState = produce(this.state, draftState => { draftState.languageSelectorState.isExpanded = !this.state.languageSelectorState.isExpanded; draftState.universeSelectorState.isExpanded = false; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } async directionButtonClick() { if (!this.state.uiControllerState.venue) { this.mapActionsDispatcher.fireError('Must be inside venue to enter in direction'); return; } const nextState = await produce(this.state, draftState => { this.defaultToDirection(draftState); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.tryToStartDirection(); if (!this.state.uiControllerState.directionFromPoint) { this.directionSearchFromQueryChange(''); } else if (!this.state.uiControllerState.directionToPoint) { this.directionSearchToQueryChange(''); } } directionFromBlur() { setTimeout(() => { const nextState = produce(this.state, draftState => { draftState.searchDirectionBarState.isFromFocus = false; if (!this.state.searchDirectionBarState.isFromFocus && !this.state.searchDirectionBarState.isToFocus) { draftState.searchResultListState.isHidden = true; draftState.searchResultListState.results = undefined; draftState.searchResultListState.universes = []; draftState.searchResultListState.currentUniverse = undefined; draftState.searchResultListState.showCurrentLocation = undefined; draftState.searchContainerState.isInSearch = false; } }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); }, 250); } directionToBlur() { setTimeout(() => { const nextState = produce(this.state, draftState => { draftState.searchDirectionBarState.isToFocus = false; if (!this.state.searchDirectionBarState.isFromFocus && !this.state.searchDirectionBarState.isToFocus) { draftState.searchResultListState.isHidden = true; draftState.searchResultListState.results = undefined; draftState.searchResultListState.universes = []; draftState.searchResultListState.currentUniverse = undefined; draftState.searchResultListState.showCurrentLocation = undefined; draftState.searchContainerState.isInSearch = false; } }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); }, 250); } async directionFromFocus() { const nextState = await produce(this.state, async draftState => { draftState.searchContainerState.isInSearch = true; draftState.searchDirectionBarState.isFromFocus = true; draftState.searchDirectionBarState.isToFocus = false; draftState.uiControllerState.status = 'inFromSearch'; draftState.bottomViewState.hidden = true; if (this.state.searchDirectionBarState.fromQuery === lang_current_location(this.state.uiControllerState.preferredLanguage)) { draftState.searchDirectionBarState.fromQuery = ''; } await this.setMainFroms(draftState); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } async directionToFocus() { const nextState = await produce(this.state, async draftState => { draftState.searchContainerState.isInSearch = true; draftState.searchDirectionBarState.isToFocus = true; draftState.searchDirectionBarState.isFromFocus = false; draftState.uiControllerState.status = 'inToSearch'; draftState.bottomViewState.hidden = true; await this.setMainFroms(draftState); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } directionBackButtonClick() { const nextState = produce(this.state, draftState => { this.directionToDefault(draftState); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } changeDirectionModes(modes) { const nextState = produce(this.state, draftState => { var _draftState$uiControl; draftState.searchDirectionBarState.modes = modes; if (!draftState.uiControllerState.directionMode || draftState.uiControllerState.directionMode && !modes.map(mode => mode._id).includes((_draftState$uiControl = draftState.uiControllerState.directionMode) === null || _draftState$uiControl === void 0 ? void 0 : _draftState$uiControl._id)) { draftState.searchDirectionBarState.selectedMode = modes[0]; draftState.uiControllerState.directionMode = modes[0]; } else { draftState.searchDirectionBarState.selectedMode = this.state.uiControllerState.directionMode; } }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } changeDirectionMode(mode) { const nextState = produce(this.state, draftState => { draftState.searchDirectionBarState.selectedMode = mode; draftState.uiControllerState.directionMode = mode; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.tryToStartDirection(); } searchBackButtonClick() { const nextState = produce(this.state, draftState => { this.searchToDefault(draftState); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } searchResultsChange(results) { const nextState = produce(this.state, draftState => { draftState.searchResultListState.results = results; draftState.searchResultListState.showCurrentLocation = undefined; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } searchFocus() { const nextState = produce(this.state, draftState => { this.defaultToSearch(draftState); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } async setMainFroms(draftState) { var _this$state$uiControl; const searchResults = await this.apiService.getMainFroms((_this$state$uiControl = this.state.uiControllerState) === null || _this$state$uiControl === void 0 ? void 0 : _this$state$uiControl.venue); draftState.searchResultListState.results = buildSearchResult(searchResults, this.state.uiControllerState.language); draftState.searchResultListState.showCurrentLocation = this.mapActionsDispatcher.hasIndoorLocation() ? lang_current_location(this.state.uiControllerState.preferredLanguage) : undefined; } async setMainSearches(draftState) { const searchResults = await this.apiService.getMainSearches(this.state.uiControllerState.venue); draftState.searchResultListState.results = buildSearchResult(searchResults, this.state.uiControllerState.language); draftState.searchResultListState.showCurrentLocation = undefined; } searchBlur() { setTimeout(() => { if (!this.state.searchDirectionBarState.isFromFocus && !this.state.searchDirectionBarState.isToFocus) { const nextState = produce(this.state, draftState => { this.searchToDefault(draftState); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } }, 500); } async searchQueryChange(query) { const nextState = produce(this.state, draftState => { draftState.searchBarState.searchQuery = query; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); let searchResults; if (this.state.uiControllerState.venue) { const searchParams = { query, objectClasses: ['place', 'placeList'], venueId: this.state.uiControllerState.venue._id }; if (query.length === 0) { searchResults = await this.apiService.getMainSearches(this.state.uiControllerState.venue); } else { searchResults = await this.apiService.search(searchParams); } } else { const searchParams = { query, objectClasses: ['venue'] }; searchResults = await this.apiService.search(searchParams); } const nextStateAsync = await produce(this.state, async draftState => { draftState.searchResultListState.results = buildSearchResult(searchResults, this.state.uiControllerState.language); draftState.searchResultListState.universes = this.state.universeSelectorState.universes; draftState.searchResultListState.currentUniverse = this.state.universeSelectorState.selectedUniverse; draftState.searchResultListState.showCurrentLocation = undefined; }); const oldStateAsync = this.state; this.state = nextStateAsync; this.render(oldStateAsync, nextStateAsync); } async directionSearchFromQueryChange(query) { var _this$state$universeS, _this$state$uiControl2; const nextState = produce(this.state, draftState => { draftState.searchContainerState.isInSearch = true; draftState.searchDirectionBarState.isInSearch = true; draftState.searchDirectionBarState.fromQuery = query; draftState.searchResultListState.isHidden = false; draftState.searchResultListState.isInDirectionSearch = true; draftState.bottomViewState.hidden = true; draftState.uiControllerState.status = 'inFromSearch'; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); const searchParams = { query, objectClasses: ['place'], universeId: (_this$state$universeS = this.state.universeSelectorState.selectedUniverse) === null || _this$state$universeS === void 0 ? void 0 : _this$state$universeS._id, venueId: (_this$state$uiControl2 = this.state.uiControllerState.venue) === null || _this$state$uiControl2 === void 0 ? void 0 : _this$state$uiControl2._id }; let searchResults; if (query.length === 0) { searchResults = await this.apiService.getMainFroms(this.state.uiControllerState.venue); } else { searchResults = await this.apiService.search(searchParams); } const nextStateAsync = await produce(this.state, async draftState => { draftState.searchResultListState.results = buildSearchResult(searchResults, this.state.uiControllerState.language); draftState.searchResultListState.showCurrentLocation = this.mapActionsDispatcher.hasIndoorLocation() ? lang_current_location(this.state.uiControllerState.preferredLanguage) : undefined; draftState.searchResultListState.universes = []; draftState.searchResultListState.currentUniverse = undefined; }); const oldStateAsync = this.state; this.state = nextStateAsync; this.render(oldStateAsync, nextStateAsync); } async directionSearchToQueryChange(query) { var _this$state$universeS2, _this$state$uiControl3; this.generic(draftState => { draftState.searchContainerState.isInSearch = true; draftState.searchDirectionBarState.isInSearch = true; draftState.searchDirectionBarState.toQuery = query; draftState.searchResultListState.isHidden = false; draftState.searchResultListState.isInDirectionSearch = true; draftState.bottomViewState.hidden = true; draftState.uiControllerState.status = 'inToSearch'; }); const searchParams = { query, objectClasses: ['place', 'placeList'], universeId: (_this$state$universeS2 = this.state.universeSelectorState.selectedUniverse) === null || _this$state$universeS2 === void 0 ? void 0 : _this$state$universeS2._id, venueId: (_this$state$uiControl3 = this.state.uiControllerState.venue) === null || _this$state$uiControl3 === void 0 ? void 0 : _this$state$uiControl3._id }; let searchResults; if (query.length === 0) { searchResults = await this.apiService.getMainSearches(this.state.uiControllerState.venue); } else { searchResults = await this.apiService.search(searchParams); } const nextStateAsync = await produce(this.state, async draftState => { draftState.searchResultListState.results = buildSearchResult(searchResults, this.state.uiControllerState.language); draftState.searchResultListState.showCurrentLocation = undefined; draftState.searchResultListState.universes = []; draftState.searchResultListState.currentUniverse = undefined; }); const oldStateAsync = this.state; this.state = nextStateAsync; this.render(oldStateAsync, nextStateAsync); } // TODO use it everywhere generic(producer) { const nextState = produce(this.state, producer); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } selectSearchResult(result, universe) { if (this.state.uiControllerState.status === 'inFromSearch') { this.selectFrom(result); if (this.state.searchDirectionBarState.toQuery === undefined || this.state.searchDirectionBarState.toQuery === '') { this.directionSearchToQueryChange(''); } } else if (this.state.uiControllerState.status === 'inToSearch') { this.selectTo(result); } else if (this.state.uiControllerState.status === 'inSearch') { this.selectDefaultSearchResult(result, universe); } } async selectDefaultSearchResult(result, universe) { if (result.objectClass === 'Place') { await this.selectPlace(result); this.mapActionsDispatcher.centerOnPlace(result); if (universe) { this.mapActionsDispatcher.setUniverse(universe); } } if (result.objectClass === 'Placelist') { this.selectPlacelist(result); // TODO Verify this.mapActionsDispatcher.selectPlacelist(result, { channel: 'search', searchQuery: this.state.searchBarState.searchQuery }) } const nextState = produce(this.state, draftState => { draftState.searchResultListState.isHidden = true; draftState.searchBarState.isInSearch = false; draftState.searchBarState.searchQuery = ''; draftState.searchContainerState.isInSearch = false; draftState.uiControllerState.status = 'default'; draftState.searchResultListState.results = undefined; draftState.searchResultListState.universes = []; draftState.searchResultListState.currentUniverse = undefined; draftState.searchResultListState.showCurrentLocation = undefined; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); if (result.objectClass === 'Venue') { this.mapActionsDispatcher.centerOnVenue(result); } } selectCurrentLocation() { const nextState = produce(this.state, draftState => { draftState.uiControllerState.directionFromPoint = this.mapActionsDispatcher.getUserLocation(); draftState.searchDirectionBarState.fromQuery = lang_current_location(this.state.uiControllerState.preferredLanguage); this.setNextDirectionStep(draftState); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.tryToStartDirection(); } async selectFrom(result) { const nextState = produce(this.state, draftState => { this.setFromSelected(draftState, result); this.setNextDirectionStep(draftState); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.tryToStartDirection(); } async selectTo(result) { if (result.objectClass === 'Place') {// this.selectPlace(result); } if (result.objectClass === 'Placelist') { this.selectPlacelist(result); } const nextState = produce(this.state, draftState => { this.setToSelected(draftState, result); this.setNextDirectionStep(draftState); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.tryToStartDirection(); } willEnterInVenue(venue) { const nextState = produce(this.state, draftState => { draftState.searchBarState.searchPlaceholder = lang_entering_venue(this.state.uiControllerState.language, venue.name); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } enterInVenue(venue) { const nextState = produce(this.state, draftState => { if (this.state.uiControllerState.direction) { if (!this.state.uiControllerState.lastExitedVenue || venue._id === this.state.uiControllerState.lastExitedVenue._id) { this.enterVenueInDirection(draftState); } else { this.directionToDefault(draftState); } } if (this.state.uiControllerState.selectedContent) { if (!this.state.uiControllerState.lastExitedVenue || venue._id === this.state.uiControllerState.lastExitedVenue._id) { this.enterVenueInSelectedContent(draftState); if (this.state.uiControllerState.selectedContent.objectClass === 'Place' || this.state.uiControllerState.selectedContent.objectClass === 'PlaceDetails') { setTimeout(() => this.mapActionsDispatcher.selectPlace(this.state.uiControllerState.selectedContent, true), 500); } else if (this.state.uiControllerState.selectedContent.objectClass === 'Placelist') { setTimeout(() => this.mapActionsDispatcher.selectPlacelist(this.state.uiControllerState.selectedContent), 500); } } else { draftState.mapwizeMapState.selectedPlace = undefined; draftState.uiControllerState.selectedContent = undefined; draftState.bottomViewState.content = undefined; draftState.bottomViewState.expanded = false; draftState.bottomViewState.hidden = true; draftState.languageSelectorState.isHidden = draftState.languageSelectorState.languages.length <= 1; draftState.universeSelectorState.isHidden = draftState.universeSelectorState.universes.length <= 1; this.mapActionsDispatcher.unselectContent(); } } draftState.searchBarState.searchPlaceholder = lang_search_venue(this.state.uiControllerState.language, titleForLanguage(venue, this.state.uiControllerState.language)); draftState.uiControllerState.venue = venue; draftState.searchBarState.directionButtonHidden = false; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } exitVenue(venue) { const nextState = produce(this.state, draftState => { draftState.searchBarState.searchPlaceholder = lang_search_global(this.state.uiControllerState.language); draftState.uiControllerState.lastExitedVenue = venue; draftState.uiControllerState.venue = undefined; draftState.searchBarState.directionButtonHidden = true; if (this.state.uiControllerState.direction) { this.directionToExitVenue(draftState); } else if (this.state.uiControllerState.selectedContent) { this.selectedContentToExitVenue(draftState); } }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } changeFloors(floors) { const nextState = produce(this.state, draftState => { draftState.uiControllerState.floors = floors; draftState.floorControllerState.floors = buildFloorDisplays(floors, this.state.uiControllerState.language); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } loadFloor(floor) { const nextState = produce(this.state, draftState => { draftState.floorControllerState.loadingFloor = floor; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } changeFloor(floor) { const nextState = produce(this.state, draftState => { draftState.floorControllerState.loadingFloor = undefined; draftState.floorControllerState.selectedFloor = floor; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } changeUniverses(universes) { const nextState = produce(this.state, draftState => { draftState.universeSelectorState.universes = universes; draftState.universeSelectorState.isHidden = universes.length <= 1; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } loadUniverse() {} changeUniverse(universe) { const nextState = produce(this.state, draftState => { draftState.universeSelectorState.selectedUniverse = universe; draftState.universeSelectorState.isExpanded = false; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } changeLanguages(languages) { const nextState = produce(this.state, draftState => { draftState.languageSelectorState.languages = buildLanguageDisplays(languages); draftState.languageSelectorState.isHidden = languages.length <= 1; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } changeLanguage(language) { const nextState = produce(this.state, draftState => { draftState.languageSelectorState.selectedLanguage = buildLanguageDisplay(language); draftState.languageSelectorState.isExpanded = false; draftState.uiControllerState.language = language; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } selectContent(content) { const nextState = produce(this.state, draftState => { draftState.uiControllerState.selectedContent = content; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } async externalSelectPlace(place) { this.selectPlace(place); return this.mapActionsDispatcher.centerOnPlace(place); } async externalSelectPlacelist(placelist) { this.selectPlacelist(placelist); return this.mapActionsDispatcher.centerOnPlacelist(placelist); } onPlaceClick(place) { if (this.state.uiControllerState.status === 'default') { this.selectPlace(place); } if (this.state.uiControllerState.status === 'inFromSearch') { this.selectFrom(place); return; } else if (this.state.uiControllerState.status === 'inToSearch') { this.selectTo(place); return; } else if (this.state.uiControllerState.status === 'inDirection') { return; } } onVenueClick(venue) { this.mapActionsDispatcher.centerOnVenue(venue); } onMapClick(coordinate) { if (this.state.uiControllerState.status === 'default') { const nextState = produce(this.state, draftState => { draftState.mapwizeMapState.selectedPlace = undefined; draftState.uiControllerState.selectedContent = undefined; draftState.bottomViewState.content = undefined; draftState.bottomViewState.expanded = false; draftState.bottomViewState.hidden = true; draftState.languageSelectorState.isExpanded = false; draftState.languageSelectorState.isHidden = draftState.languageSelectorState.languages.length <= 1; draftState.universeSelectorState.isExpanded = false; draftState.universeSelectorState.isHidden = draftState.universeSelectorState.universes.length <= 1; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.mapActionsDispatcher.unselectContent(); } else if (this.state.uiControllerState.status === 'inFromSearch' && this.state.searchDirectionBarState.isFromFocus) { const nextState = produce(this.state, draftState => { this.setFromCoordinateSelected(draftState, coordinate); this.setNextDirectionStep(draftState); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.tryToStartDirection(); } else if (this.state.uiControllerState.status === 'inToSearch' && this.state.searchDirectionBarState.isToFocus) { const nextState = produce(this.state, draftState => { this.setToCoordinateSelected(draftState, coordinate); this.setNextDirectionStep(draftState); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.tryToStartDirection(); } } toggleBottomViewExpand() { const nextState = produce(this.state, draftState => { draftState.bottomViewState.expanded = !draftState.bottomViewState.expanded; draftState.searchBarState.isHidden = draftState.bottomViewState.expanded; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } async selectPlace(placePreview) { const nextState = produce(this.state, draftState => { if (this.state.uiControllerState.venue) { draftState.bottomViewState.hidden = false; draftState.languageSelectorState.isHidden = true; draftState.universeSelectorState.isHidden = true; } draftState.bottomViewState.content = { ...placePreview, titleLabel: placePreview === null || placePreview === void 0 ? void 0 : placePreview.title, subtitleLabel: placePreview === null || placePreview === void 0 ? void 0 : placePreview.subtitle }; draftState.uiControllerState.selectedContent = placePreview; draftState.mapwizeMapState.selectedPlace = placePreview; draftState.mapwizeMapState.markers = []; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); await this.getDetailsForPlacePreview({ ...placePreview }); } async getDetailsForPlacePreview(placePreview) { let place = placePreview; let details = placePreview; if (placePreview.objectClass === 'PlacePreview') { place = await this.apiService.getPlace(placePreview); details = await this.apiService.getPlaceDetails(placePreview); } else if (placePreview.objectClass === 'Place') { details = await this.apiService.getPlaceDetails(placePreview); } const nextState = produce(this.state, draftState => { if (this.state.uiControllerState.venue) { draftState.bottomViewState.hidden = false; draftState.languageSelectorState.isHidden = true; draftState.universeSelectorState.isHidden = true; } draftState.bottomViewState.content = buildPlaceDetails(details, this.state.uiControllerState.language); draftState.uiControllerState.selectedContent = place; draftState.mapwizeMapState.selectedPlace = place; draftState.mapwizeMapState.markers = []; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } async selectPlaceAndGoDirection(place) { var _this$state$mapwizeMa; if (((_this$state$mapwizeMa = this.state.mapwizeMapState.selectedPlace) === null || _this$state$mapwizeMa === void 0 ? void 0 : _this$state$mapwizeMa._id) !== (place === null || place === void 0 ? void 0 : place._id)) { await this.selectPlace(place); } this.directionButtonClick(); this.tryToStartDirection(); } async selectPlacelist(placelist) { const places = await this.apiService.getPlacesForPlacelist(placelist); const nextState = produce(this.state, draftState => { if (this.state.uiControllerState.venue) { draftState.bottomViewState.hidden = false; draftState.languageSelectorState.isHidden = true; draftState.universeSelectorState.isHidden = true; } draftState.bottomViewState.content = buildPlacelistDetails(placelist, places, this.state.uiControllerState.language); draftState.uiControllerState.selectedContent = placelist; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); if (this.state.uiControllerState.status !== 'inDirection') { this.mapActionsDispatcher.selectPlacelist(placelist); } } getFrom() { return this.state.uiControllerState.directionFromPoint; } getTo() { return this.state.uiControllerState.directionToPoint; } setMode(modeId) { const mode = this.state.searchDirectionBarState.modes.find(m => m._id === modeId); if (!mode) { console.error('Mode does not exist in this venue'); return; } const nextState = produce(this.state, draftState => { draftState.searchDirectionBarState.selectedMode = mode; draftState.uiControllerState.directionMode = mode; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.tryToStartDirection(); } setFromSelected(draftState, from) { draftState.uiControllerState.directionFromPoint = from; draftState.searchDirectionBarState.fromQuery = titleForLanguage(from, draftState.uiControllerState.language) || ''; } setFromCoordinateSelected(draftState, from) { draftState.uiControllerState.directionFromPoint = from; draftState.searchDirectionBarState.fromQuery = lang_coordinates(this.state.uiControllerState.language); } setToSelected(draftState, to) { draftState.uiControllerState.directionToPoint = to; draftState.searchDirectionBarState.toQuery = titleForLanguage(to, draftState.uiControllerState.language) || ''; } setToCoordinateSelected(draftState, to) { draftState.uiControllerState.directionToPoint = to; draftState.searchDirectionBarState.toQuery = lang_coordinates(this.state.uiControllerState.language); } setNextDirectionStep(draftState) { if (!draftState.uiControllerState.directionFromPoint) { draftState.searchDirectionBarState.isFromFocus = true; draftState.searchResultListState.results = undefined; draftState.searchResultListState.universes = []; draftState.searchResultListState.currentUniverse = undefined; draftState.searchResultListState.showCurrentLocation = undefined; } else if (!draftState.uiControllerState.directionToPoint) { draftState.searchDirectionBarState.isToFocus = true; draftState.searchResultListState.results = undefined; draftState.searchResultListState.universes = []; draftState.searchResultListState.currentUniverse = undefined; draftState.searchResultListState.showCurrentLocation = undefined; } else { draftState.searchResultListState.isInDirectionSearch = false; draftState.searchResultListState.isHidden = true; draftState.searchResultListState.results = undefined; draftState.searchResultListState.universes = []; draftState.searchResultListState.currentUniverse = undefined; draftState.searchResultListState.showCurrentLocation = undefined; draftState.searchContainerState.isInSearch = false; draftState.uiControllerState.status = 'inDirection'; } } onCameraChange(camera) { const nextState = produce(this.state, draftState => { draftState.uiControllerState.heading = camera.bearing; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } swapFromAndTo() { const nextState = produce(this.state, draftState => { const oldFrom = this.state.uiControllerState.directionFromPoint; const oldTo = this.state.uiControllerState.directionToPoint; const oldFromQuery = this.state.searchDirectionBarState.fromQuery; const oldToQuery = this.state.searchDirectionBarState.toQuery; if ((oldTo === null || oldTo === void 0 ? void 0 : oldTo.objectClass) === 'Placelist') { draftState.uiControllerState.directionFromPoint = undefined; draftState.searchDirectionBarState.fromQuery = ''; } else { draftState.uiControllerState.directionFromPoint = oldTo; draftState.searchDirectionBarState.fromQuery = oldToQuery; } draftState.uiControllerState.directionToPoint = oldFrom; draftState.searchDirectionBarState.toQuery = oldFromQuery; if ((oldFrom === null || oldFrom === void 0 ? void 0 : oldFrom.objectClass) === 'Place' || (oldFrom === null || oldFrom === void 0 ? void 0 : oldFrom.objectClass) === 'PlaceDetails') { this.selectPlace(oldFrom); } this.setNextDirectionStep(draftState); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.tryToStartDirection(); } async tryToStartDirection() { if (this.state.uiControllerState.status !== 'default' && this.state.uiControllerState.directionFromPoint && this.state.uiControllerState.directionToPoint) { try { if (this.state.uiControllerState.directionFromPoint.objectClass === 'LatLngFloor' && this.mapActionsDispatcher.hasIndoorLocation()) { this.startNavigation(); } else { var _this$devCallbackInte, _this$devCallbackInte2; let direction = this.state.uiControllerState.venue && this.state.universeSelectorState.selectedUniverse && this.state.uiControllerState.directionMode && (await ((_this$devCallbackInte = (_this$devCallbackInte2 = this.devCallbackInterceptor).onDirectionWillStart) === null || _this$devCallbackInte === void 0 ? void 0 : _this$devCallbackInte.call(_this$devCallbackInte2, this.state.uiControllerState.venue, this.state.universeSelectorState.selectedUniverse, this.state.uiControllerState.directionFromPoint, this.state.uiControllerState.directionToPoint, this.state.uiControllerState.directionMode, false))); if (direction === undefined) { direction = await this.apiService.getDirection({ from: this.buildDirectionPoint(this.state.uiControllerState.directionFromPoint), to: this.buildDirectionPoint(this.state.uiControllerState.directionToPoint), mode: this.state.uiControllerState.directionMode }); } const nextState = produce(this.state, draftState => { this.setNextDirectionStep(draftState); draftState.uiControllerState.direction = direction; draftState.bottomViewState.directionContent = buildDirectionInfo(direction, this.state.uiControllerState.unit); draftState.bottomViewState.hidden = false; draftState.bottomViewState.expanded = false; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.mapActionsDispatcher.unselectContent(); this.startDirection(direction, new DirectionOptions()); } } catch (e) { const nextState = produce(this.state, draftState => { this.setNextDirectionStep(draftState); draftState.uiControllerState.direction = undefined; draftState.bottomViewState.directionContent = buildDirectionError(this.state.uiControllerState.preferredLanguage); draftState.bottomViewState.hidden = false; draftState.bottomViewState.expanded = false; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.mapActionsDispatcher.stopDirection(); } } } async directionObjectToMapwizeObject(directionPointWrapper) { if (directionPointWrapper.placeId) { const place = await this.apiService.getPlaceWithId(directionPointWrapper.placeId); return place; } else { return Promise.resolve(directionPointWrapper); } } async startDirectionFromProps(directionProp) { if (directionProp === undefined || directionProp.direction == undefined) { this.directionBackButtonClick(); return; } const direction = directionProp.direction; const [from, to] = await Promise.all([this.directionObjectToMapwizeObject(direction.from), this.directionObjectToMapwizeObject(direction.to)]); const nextState = await produce(this.state, async draftState => { draftState.searchBarState.searchQuery = ''; draftState.searchBarState.isHidden = true; draftState.searchBarState.isInSearch = false; draftState.searchResultListState.isHidden = true; draftState.searchResultListState.results = undefined; draftState.searchResultListState.universes = []; draftState.searchResultListState.currentUniverse = undefined; draftState.searchResultListState.showCurrentLocation = undefined; draftState.searchDirectionBarState.isHidden = false; draftState.universeSelectorState.isHidden = true; draftState.languageSelectorState.isHidden = true; draftState.searchResultListState.isInDirectionSearch = false; draftState.searchContainerState.isInSearch = false; draftState.uiControllerState.status = 'inDirection'; if (to.objectClass === 'Place') { const details = await this.apiService.getPlaceDetailsWithId(to._id); draftState.bottomViewState.content = buildPlaceDetails(details, draftState.uiControllerState.preferredLanguage); } draftState.uiControllerState.status = 'inDirection'; draftState.uiControllerState.direction = direction; draftState.uiControllerState.directionFromPoint = from; draftState.uiControllerState.directionToPoint = to; draftState.uiControllerState.directionMode = direction.mode; draftState.bottomViewState.directionContent = buildDirectionInfo(direction, draftState.uiControllerState.unit); draftState.searchDirectionBarState.fromQuery = from.objectClass === 'Place' ? titleForLanguage(from, draftState.uiControllerState.preferredLanguage) : lang_coordinates(draftState.uiControllerState.preferredLanguage); draftState.searchDirectionBarState.toQuery = to.objectClass === 'Place' ? titleForLanguage(to, draftState.uiControllerState.preferredLanguage) : lang_coordinates(draftState.uiControllerState.preferredLanguage); draftState.bottomViewState.hidden = false; draftState.bottomViewState.expanded = false; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.mapActionsDispatcher.unselectContent(); this.startDirection(direction, directionProp.directionOptions); } async startNavigationFromProps(navigationProp) { if (navigationProp === undefined || navigationProp.destination === undefined) { this.directionBackButtonClick(); return; } const from = this.mapActionsDispatcher.getUserLocation(); const to = navigationProp.destination; const nextState = await produce(this.state, async draftState => { draftState.searchBarState.searchQuery = ''; draftState.searchBarState.isHidden = true; draftState.searchBarState.isInSearch = false; draftState.searchResultListState.isHidden = true; draftState.searchResultListState.results = undefined; draftState.searchResultListState.universes = []; draftState.searchResultListState.currentUniverse = undefined; draftState.searchResultListState.showCurrentLocation = undefined; draftState.searchDirectionBarState.isHidden = false; draftState.universeSelectorState.isHidden = true; draftState.languageSelectorState.isHidden = true; draftState.searchResultListState.isInDirectionSearch = false; draftState.searchContainerState.isInSearch = false; draftState.uiControllerState.status = 'inDirection'; const toObject = to; if (toObject.objectClass === 'Place') { const details = await this.apiService.getPlaceDetailsWithId(toObject._id); draftState.bottomViewState.content = buildPlaceDetails(details, draftState.uiControllerState.preferredLanguage); } draftState.uiControllerState.status = 'inDirection'; draftState.uiControllerState.directionToPoint = navigationProp.destination; draftState.uiControllerState.directionMode = navigationProp.directionMode; draftState.uiControllerState.directionFromPoint = from; draftState.searchDirectionBarState.fromQuery = lang_current_location(this.state.uiControllerState.preferredLanguage); draftState.searchDirectionBarState.toQuery = (toObject === null || toObject === void 0 ? void 0 : toObject.objectClass) === 'Place' ? titleForLanguage(toObject, draftState.uiControllerState.preferredLanguage) : lang_coordinates(draftState.uiControllerState.preferredLanguage); draftState.bottomViewState.hidden = false; draftState.bottomViewState.expanded = false; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); this.mapActionsDispatcher.unselectContent(); this.startNavigation(navigationProp); } startNavigation(navigationProp) { var _this$devCallbackInte3, _this$devCallbackInte4; const navigationPropFull = navigationProp || new NavigationProp(this.state.uiControllerState.directionToPoint, this.state.uiControllerState.directionMode, new DirectionOptions(), 15); const userNavigation = this.state.uiControllerState.venue && this.state.universeSelectorState.selectedUniverse && ((_this$devCallbackInte3 = (_this$devCallbackInte4 = this.devCallbackInterceptor).onNavigationRequested) === null || _this$devCallbackInte3 === void 0 ? void 0 : _this$devCallbackInte3.call(_this$devCallbackInte4, this.state.uiControllerState.venue, this.state.universeSelectorState.selectedUniverse, navigationPropFull)); this.mapActionsDispatcher.startNavigation(userNavigation !== undefined ? userNavigation : navigationPropFull); } updateNavigationInfo(navigationInfo) { const nextState = produce(this.state, draftState => { draftState.bottomViewState.directionContent = buildNavigationInfo(navigationInfo, this.state.uiControllerState.unit); draftState.bottomViewState.hidden = false; draftState.bottomViewState.expanded = false; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } startDirection(direction, directionOptions) { var _this$state$uiControl4, _this$state$uiControl5, _this$state$uiControl6, _this$state$uiControl7; let fromLabel = lang_start(this.state.uiControllerState.language); let toLabel = lang_destination(this.state.uiControllerState.language); if (((_this$state$uiControl4 = this.state.uiControllerState.directionFromPoint) === null || _this$state$uiControl4 === void 0 ? void 0 : _this$state$uiControl4.objectClass) === 'Place' || ((_this$state$uiControl5 = this.state.uiControllerState.directionFromPoint) === null || _this$state$uiControl5 === void 0 ? void 0 : _this$state$uiControl5.objectClass) === 'Placelist') { fromLabel = this.state.searchDirectionBarState.fromQuery; } if (((_this$state$uiControl6 = this.state.uiControllerState.directionToPoint) === null || _this$state$uiControl6 === void 0 ? void 0 : _this$state$uiControl6.objectClass) === 'Place' || ((_this$state$uiControl7 = this.state.uiControllerState.directionToPoint) === null || _this$state$uiControl7 === void 0 ? void 0 : _this$state$uiControl7.objectClass) === 'Placelist') { toLabel = this.state.searchDirectionBarState.toQuery; } this.mapActionsDispatcher.startDirection(direction, directionOptions, fromLabel, toLabel); } buildDirectionPoint(point) { return point; } defaultToSearch(draftState) { draftState.searchContainerState.isInSearch = true; draftState.searchBarState.isInSearch = true; draftState.searchBarState.searchQuery = ''; draftSt