From d8e4b4c41d312be4e887d71f785e17e5785aee79 Mon Sep 17 00:00:00 2001 From: shafi54 <108669266+shafi-aviz@users.noreply.github.com> Date: Tue, 13 Oct 2026 14:18:07 +0530 Subject: [PATCH] enh --- apps/user-ui/src/components/LocationBar.tsx | 46 +++++++- apps/web-ui/src/routes/location-selector.tsx | 108 +++++++++++++++---- change-log.txt | 35 ++++++ 3 files changed, 165 insertions(+), 24 deletions(-) diff --git a/apps/user-ui/src/components/LocationBar.tsx b/apps/user-ui/src/components/LocationBar.tsx index 92f631f..7baef2a 100644 --- a/apps/user-ui/src/components/LocationBar.tsx +++ b/apps/user-ui/src/components/LocationBar.tsx @@ -3,18 +3,45 @@ import { View } from 'react-native' import MaterialIcons from '@expo/vector-icons/MaterialIcons' import { tw, theme, MyText, MyTouchableOpacity } from 'common-ui' import { useRegion } from '@/src/hooks/useRegion' +import { useAddressStore } from '@/src/store/addressStore' +import { useAuthOptional } from '@/src/contexts/AuthContext' +import { trpc } from '@/src/trpc-client' import AddressSwitcherSheet from '@/src/components/location/AddressSwitcherSheet' +const formatAddress = (address: { + addressLine1: string + addressLine2?: string | null + city: string + pincode: string +}) => + `${address.addressLine1}${address.addressLine2 ? `, ${address.addressLine2}` : ''}, ${address.city} - ${address.pincode}` + /** * Location bar shown at the top of every top-level tab screen. * Rendered INSIDE the scroll content (first item / ListHeaderComponent) so it * scrolls out with the page instead of sticking. Tapping opens the address * switcher: pick a saved address (region follows it) or add a new one. + * + * Shows "Deliver to: " (truncated) on the first line and the active + * address beneath it. */ const LocationBar: React.FC = () => { const [sheetOpen, setSheetOpen] = useState(false) const { region } = useRegion() + const isAuthenticated = useAuthOptional()?.isAuthenticated ?? false + const selectedAddressId = useAddressStore((state) => state.selectedAddressId) + const { data: addressesData } = trpc.user.address.getUserAddresses.useQuery(undefined, { + enabled: isAuthenticated, + }) + + const addresses = addressesData?.data ?? [] + // Prefer the address the user selected at checkout, else their default. + const activeAddress = + addresses.find((address) => address.id === selectedAddressId) ?? + addresses.find((address) => address.isDefault) ?? + null + return ( { - - Deliver to - - - {region?.name ?? 'Choose your address'} + + Deliver to:{' '} + + {region?.name ?? 'Choose your address'} + + {activeAddress ? ( + + {formatAddress(activeAddress)} + + ) : null} diff --git a/apps/web-ui/src/routes/location-selector.tsx b/apps/web-ui/src/routes/location-selector.tsx index 58c6ffb..e859a9a 100644 --- a/apps/web-ui/src/routes/location-selector.tsx +++ b/apps/web-ui/src/routes/location-selector.tsx @@ -36,13 +36,27 @@ interface GoogleMarker { setMap: (map: GoogleMap | null) => void setPosition: (position: LatLngLiteral) => void } +interface GoogleMapConstructor { + new (element: HTMLElement, options: Record): GoogleMap +} +interface GoogleMarkerConstructor { + new (options: Record): GoogleMarker +} +// The resolved `maps` + `marker` libraries (both constructors present). +interface GoogleMapsApi { + Map: GoogleMapConstructor + Marker: GoogleMarkerConstructor +} +type GoogleImportLibrary = (library: string, ...rest: string[]) => Promise +// The global `google.maps` namespace, including the dynamic-import entry point. interface GoogleMapsNamespace { - Map: new (element: HTMLElement, options: Record) => GoogleMap - Marker: new (options: Record) => GoogleMarker + importLibrary?: GoogleImportLibrary + // Set by the bootstrap; the API invokes it once the namespace is fully ready. + __ib__?: () => void } type ReactNativeWebViewBridge = { postMessage: (message: string) => void } type GoogleWindow = Window & { - google?: { maps: GoogleMapsNamespace } + google?: { maps?: GoogleMapsNamespace } // Injected by react-native-webview when this page is embedded in user-ui. ReactNativeWebView?: ReactNativeWebViewBridge } @@ -56,26 +70,82 @@ const DEFAULT_ZOOM = 12 // VITE_GOOGLE_MAPS_API_KEY=your-key const GOOGLE_MAPS_API_KEY = import.meta.env.VITE_GOOGLE_MAPS_API_KEY as string | undefined -let googleMapsLoader: Promise | null = null +let googleMapsLoader: Promise | null = null -function loadGoogleMaps(apiKey: string): Promise { - const existing = (window as GoogleWindow).google?.maps - if (existing) return Promise.resolve(existing) +/** + * Google's recommended "Dynamic Library Import" bootstrap + * (https://goo.gle/js-api-loading). + * + * It defines `google.maps.importLibrary` synchronously and loads the API with + * the `callback` signal, so we never read `google.maps` before it exists. A raw + * `