From 37c47adfbcd1a2876aba44c2cbf2fd448beffacf Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Fri, 3 Jan 2025 15:49:15 +0800 Subject: [PATCH] when store location is not provided added handler --- src/components/DeliveryRoutePreview.tsx | 4 ++-- src/utils/location.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/DeliveryRoutePreview.tsx b/src/components/DeliveryRoutePreview.tsx index e63e900..28635e5 100644 --- a/src/components/DeliveryRoutePreview.tsx +++ b/src/components/DeliveryRoutePreview.tsx @@ -3,7 +3,7 @@ import { Pressable, StyleSheet } from 'react-native'; import { Text, YStack, XStack, useTheme } from 'tamagui'; import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'; import { faStore, faPerson } from '@fortawesome/free-solid-svg-icons'; -import { restoreFleetbasePlace, getPlaceCoords } from '../utils/location'; +import { restoreFleetbasePlace, getPlaceCoords, createFauxPlace } from '../utils/location'; import { config } from '../utils'; import { formattedAddressFromPlace } from '../utils/location'; import MapView, { Marker, Callout } from 'react-native-maps'; @@ -36,7 +36,7 @@ const DeliveryRoutePreview = ({ children, zoom = 1, width = '100%', height = '10 const { store, currentStoreLocation } = useStoreLocations(); const { currentLocation } = useCurrentLocation(); const mapRef = useRef(null); - const start = restoreFleetbasePlace(currentStoreLocation.getAttribute('place')); + const start = currentStoreLocation === undefined ? createFauxPlace() : restoreFleetbasePlace(currentStoreLocation.getAttribute('place')); const end = restoreFleetbasePlace(currentLocation); const origin = getPlaceCoords(start); const destination = getPlaceCoords(end); diff --git a/src/utils/location.js b/src/utils/location.js index c0fbea7..0fdcca0 100644 --- a/src/utils/location.js +++ b/src/utils/location.js @@ -948,3 +948,13 @@ export function getDefaultCoordinates() { return { latitude, longitude }; } + +export function createFauxStoreLocation() { + return new StoreLocation({ + place: new Place({ location: new Point(DEFAULT_LATITUDE, DEFAULT_LONGITUDE) }), + }); +} + +export function createFauxPlace() { + return new Place({ location: new Point(DEFAULT_LATITUDE, DEFAULT_LONGITUDE) }); +}