This commit is contained in:
shafi54 2026-10-15 22:35:28 +05:30
parent 2986f18c59
commit fd5c532844
3 changed files with 109 additions and 56 deletions

View file

@ -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<AddressFormProps> = ({
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<AddressFormProps> = ({
<MyTouchableOpacity
testID="address-city-option-map"
onPress={openMapForFirstRegion}
style={tw`p-3 flex-row items-center`}
style={tw`p-3 border-b border-gray-50 flex-row items-center justify-between`}
>
<MaterialIcons name="map" size={18} color="#3B82F6" />
<MyText style={tw`text-blue-500 font-medium ml-2`}>Select in Map</MyText>
<MyText style={tw`text-gray-800`}>Select in Map</MyText>
</MyTouchableOpacity>
</View>
)}
@ -480,43 +473,56 @@ const AddressForm: React.FC<AddressFormProps> = ({
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.) */}
<BottomDialog open={mapDialog !== null} onClose={dismissMapDialog}>
{/* Region picker: the map opens focused on whichever region is chosen. */}
<BottomDialog open={mapRegionPickerOpen} onClose={closeMapRegionPicker}>
<View style={tw`p-6`}>
<View style={tw`flex-row items-center mb-3`}>
<View style={tw`flex-row items-center mb-1`}>
<View style={tw`w-10 h-10 bg-blue-50 rounded-full items-center justify-center mr-3`}>
<MaterialIcons name="map" size={20} color="#2563EB" />
</View>
<MyText style={tw`text-lg font-bold text-gray-900 flex-1`}>
{mapDialog?.regionName
? `Open the map for ${mapDialog.regionName}?`
: 'Open the map?'}
</MyText>
<MyText style={tw`text-lg font-bold text-gray-900 flex-1`}>Select a region</MyText>
</View>
<MyText style={tw`text-gray-600 text-sm`}>
{mapDialog?.regionName
? `The map will open on ${mapDialog.regionName}. Pick a point inside this region.`
: 'Pick a point on the map.'}
<MyText style={tw`text-gray-500 text-sm mb-4`}>
The map opens on the region you pick.
</MyText>
<View style={tw`flex-row gap-3 mt-6`}>
{regions.map((region) => (
<MyTouchableOpacity
testID="address-map-confirm-cancel"
onPress={dismissMapDialog}
style={tw`flex-1 border border-gray-200 py-3.5 rounded-xl items-center`}
key={region.id}
testID={`address-map-region-${region.id}`}
onPress={() => openMapAtRegion(region)}
activeOpacity={0.7}
style={tw`py-3 border-b border-gray-50 flex-row items-center justify-between`}
>
<MyText style={tw`text-gray-700 font-bold`}>Cancel</MyText>
<MyText style={tw`text-gray-800`}>{region.name}</MyText>
{region.id === (resolvedRegion?.regionId ?? browsingRegionId) && (
<MyText style={tw`text-xs text-gray-400`}>Current</MyText>
)}
</MyTouchableOpacity>
<MyTouchableOpacity
testID="address-map-confirm-open"
onPress={confirmMapDialog}
style={tw`flex-1 bg-brand500 py-3.5 rounded-xl items-center`}
>
<MyText style={tw`text-white font-bold`}>Open map</MyText>
</MyTouchableOpacity>
</View>
))}
{regions.length === 0 && (
<MyText style={tw`text-gray-400 text-sm py-3`}>No regions available</MyText>
)}
{/* After the regions: skip naming one and open the map on the first
region's bound. Styled as just another option in the list. */}
<MyTouchableOpacity
testID="address-map-region-select-in-map"
onPress={openMapForFirstRegion}
activeOpacity={0.7}
style={tw`py-3 border-b border-gray-50 flex-row items-center`}
>
<MyText style={tw`text-gray-800`}>Select in Map</MyText>
</MyTouchableOpacity>
<MyTouchableOpacity
testID="address-map-region-cancel"
onPress={closeMapRegionPicker}
style={tw`mt-3 border border-gray-200 py-3.5 rounded-xl items-center`}
>
<MyText style={tw`text-gray-700 font-bold`}>Cancel</MyText>
</MyTouchableOpacity>
</View>
</BottomDialog>

View file

@ -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<string, unknown>) => {
// 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

View file

@ -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 <region>?" confirmation with a BottomDialog listing every
region (`address-map-region-<id>`, 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.