diff --git a/apps/user-ui/src/components/AddressForm.tsx b/apps/user-ui/src/components/AddressForm.tsx index 31bc38c..1d80952 100644 --- a/apps/user-ui/src/components/AddressForm.tsx +++ b/apps/user-ui/src/components/AddressForm.tsx @@ -6,7 +6,7 @@ import { tw, MyText, MyTouchableOpacity , Checkbox , MyTextInput , LoadingDialog import MaterialIcons from '@expo/vector-icons/MaterialIcons'; import { trpc } from '../trpc-client'; import LocationMapStep from './location/LocationMapStep'; -import type { AddressFormProps } from '@packages/shared'; +import type { AddressFormProps, RegionSummary } from '@packages/shared'; import { savePendingAddress } from '@/src/lib/pending-address'; import { useRegion } from '@/src/hooks/useRegion'; import { useLocationStore } from '@/src/store/locationStore'; @@ -51,46 +51,40 @@ const AddressForm: React.FC = ({ const [cityOpen, setCityOpen] = useState(false); const cityName = regions.find((region) => region.id === resolvedRegion?.regionId)?.name ?? ''; - // The map focuses on the region the address will belong to: the region a picked - // location resolved to, else the browsing region. Its stored centre - // (first-priority bound) becomes the map's centre. - const mapRegion = - regions.find((region) => region.id === (resolvedRegion?.regionId ?? browsingRegionId)) ?? null; - /** Centre the map WebView opens on (null = the page's own default). */ const [mapCenter, setMapCenter] = useState<{ lat: number; lng: number } | null>(null); /** - * The pending "which region is this map for?" confirmation. Only the two - * location triggers ask — the City selector's "Select in Map" opens straight - * away. Null means no dialog. + * Region picker for the map: the two location triggers list every region and + * the chosen one becomes the map's centre. ("Select in Map" skips it.) */ - const [mapDialog, setMapDialog] = useState<{ regionName: string | null } | null>(null); + const [mapRegionPickerOpen, setMapRegionPickerOpen] = useState(false); const requestMapForAddressRegion = useCallback(() => { Keyboard.dismiss(); - setMapCenter(mapRegion?.center ?? null); - setMapDialog({ regionName: mapRegion?.name ?? null }); - }, [mapRegion]); + setMapRegionPickerOpen(true); + }, []); - // The City selector's fallback: no town picked, so open the map straight away, - // focused on the first region's bound (the first row of that selector). + // Picked a region in that list: open the map focused on its bound. + const openMapAtRegion = useCallback((region: RegionSummary) => { + setMapRegionPickerOpen(false); + setMapCenter(region.center ?? null); + setMapOpen(true); + }, []); + + const closeMapRegionPicker = useCallback(() => { + setMapRegionPickerOpen(false); + }, []); + + // "Select in Map" (City selector and region picker): no region named, so open + // the map straight away on the first region's bound. const openMapForFirstRegion = useCallback(() => { const firstRegion = regions[0] ?? null; setCityOpen(false); + setMapRegionPickerOpen(false); setMapCenter(firstRegion?.center ?? null); setMapOpen(true); }, [regions]); - const confirmMapDialog = useCallback(() => { - setMapDialog(null); - setMapOpen(true); - }, []); - - const dismissMapDialog = useCallback(() => { - setMapDialog(null); - setMapCenter(null); - }, []); - const closeMap = useCallback(() => { setMapOpen(false); setMapCenter(null); @@ -382,10 +376,9 @@ const AddressForm: React.FC = ({ - - Select in Map + Select in Map )} @@ -480,43 +473,56 @@ const AddressForm: React.FC = ({ message={isEdit ? "Updating address..." : "Adding address..."} /> - {/* Confirm the region before handing over to the map WebView, which opens - focused on that region's centre. ("Select in Map" skips this.) */} - + {/* Region picker: the map opens focused on whichever region is chosen. */} + - + - - {mapDialog?.regionName - ? `Open the map for ${mapDialog.regionName}?` - : 'Open the map?'} - + Select a region - - - {mapDialog?.regionName - ? `The map will open on ${mapDialog.regionName}. Pick a point inside this region.` - : 'Pick a point on the map.'} + + The map opens on the region you pick. - + {regions.map((region) => ( openMapAtRegion(region)} + activeOpacity={0.7} + style={tw`py-3 border-b border-gray-50 flex-row items-center justify-between`} > - Cancel + {region.name} + {region.id === (resolvedRegion?.regionId ?? browsingRegionId) && ( + Current + )} - - Open map - - + ))} + + {regions.length === 0 && ( + No regions available + )} + + {/* After the regions: skip naming one and open the map on the first + region's bound. Styled as just another option in the list. */} + + Select in Map + + + + Cancel + diff --git a/apps/web-ui/src/routes/location-selector.tsx b/apps/web-ui/src/routes/location-selector.tsx index e142ae7..5121f79 100644 --- a/apps/web-ui/src/routes/location-selector.tsx +++ b/apps/web-ui/src/routes/location-selector.tsx @@ -8,7 +8,13 @@ export const Route = createFileRoute('/location-selector')({ // Optional centre override (?lat=&lng=&zoom=) so the map can be opened for a // specific region; defaults to the Mahabubnagar town centre. validateSearch: (search: Record) => { + // TanStack's default search parser is parseSearchWith(JSON.parse), so + // `?lat=16.3570899` arrives here as a NUMBER, not a string. Accept both: + // requiring a string made every param validate to undefined, which dropped + // the query string from the URL entirely and left the map on its default + // centre for every region. const num = (value: unknown): number | undefined => { + if (typeof value === 'number') return Number.isFinite(value) ? value : undefined if (typeof value !== 'string' || value.trim() === '') return undefined const parsed = Number(value) return Number.isFinite(parsed) ? parsed : undefined diff --git a/change-log.txt b/change-log.txt index 1f8ccc3..d08a79c 100644 --- a/change-log.txt +++ b/change-log.txt @@ -4791,3 +4791,44 @@ user-ui the first region's bound and opens the map in the same step, skipping the dialog; the two location triggers still ask first. No other file changed. No tests run. + +2026-10-15 22:21:05 Map trigger: the dialog is now a REGION PICKER, not a confirmation. + + apps/user-ui/src/components/AddressForm.tsx + - replaced the "Open the map for ?" confirmation with a BottomDialog listing every + region (`address-map-region-`, current one marked). Picking a region opens the map + focused on that region's bound centre (its `center`), in one step. + - state: `mapDialog {regionName}` -> `mapRegionPickerOpen`; + openMapAtRegion(region) and + closeMapRegionPicker(); the now-unused `mapRegion` selector was removed. "Select in Map" + still opens straight away on the first region's bound. + No other file changed. No tests run. + +2026-10-15 22:27:30 Region picker: + "Select in Map" row after the region list. + + apps/user-ui/src/components/AddressForm.tsx + - the map-trigger region picker now ends with a "Select in Map" row + (`address-map-region-select-in-map`) below the listed regions, which opens the map + straight away on the FIRST region's bound - same behaviour as the City selector's row. + - openMapForFirstRegion() also closes the picker, so it serves both entry points. + No other file changed. No tests run. + +2026-10-15 22:31:10 "Select in Map" is no longer highlighted - it reads as a normal list option. + + apps/user-ui/src/components/AddressForm.tsx + - dropped the blue icon + blue label from both "Select in Map" rows (region picker and City + selector) so they read as plain options, matching the region rows (text-gray-800, same + row padding/border). MaterialIcons is still used elsewhere in the file. + No other file changed. No tests run. + +2026-10-15 22:52:40 FIX: the map page ignored ?lat/?lng, so every region opened on the default + centre (Mahabubnagar) - i.e. "all regions show the first region's area". + + apps/web-ui/src/routes/location-selector.tsx + - validateSearch's num() required a STRING, but TanStack Router's default parser is + parseSearchWith(JSON.parse): `?lat=16.3570899` arrives already as a NUMBER. Every param + therefore validated to undefined and the router rewrote the URL with no search at all + (verified in a browser: location.search === '' after loading with params), leaving the map + on MAHABUBNAGAR_CENTER. + - num() now accepts a number as well as a numeric string. + Pre-existing bug (the ?lat=&lng=&zoom= support was there but never actually worked); the + region-centre work is what surfaced it. No other file changed. No tests run.