enh
This commit is contained in:
parent
2986f18c59
commit
fd5c532844
3 changed files with 109 additions and 56 deletions
|
|
@ -6,7 +6,7 @@ import { tw, MyText, MyTouchableOpacity , Checkbox , MyTextInput , LoadingDialog
|
||||||
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
|
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
|
||||||
import { trpc } from '../trpc-client';
|
import { trpc } from '../trpc-client';
|
||||||
import LocationMapStep from './location/LocationMapStep';
|
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 { savePendingAddress } from '@/src/lib/pending-address';
|
||||||
import { useRegion } from '@/src/hooks/useRegion';
|
import { useRegion } from '@/src/hooks/useRegion';
|
||||||
import { useLocationStore } from '@/src/store/locationStore';
|
import { useLocationStore } from '@/src/store/locationStore';
|
||||||
|
|
@ -51,46 +51,40 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
||||||
const [cityOpen, setCityOpen] = useState(false);
|
const [cityOpen, setCityOpen] = useState(false);
|
||||||
const cityName = regions.find((region) => region.id === resolvedRegion?.regionId)?.name ?? '';
|
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). */
|
/** Centre the map WebView opens on (null = the page's own default). */
|
||||||
const [mapCenter, setMapCenter] = useState<{ lat: number; lng: number } | null>(null);
|
const [mapCenter, setMapCenter] = useState<{ lat: number; lng: number } | null>(null);
|
||||||
/**
|
/**
|
||||||
* The pending "which region is this map for?" confirmation. Only the two
|
* Region picker for the map: the two location triggers list every region and
|
||||||
* location triggers ask — the City selector's "Select in Map" opens straight
|
* the chosen one becomes the map's centre. ("Select in Map" skips it.)
|
||||||
* away. Null means no dialog.
|
|
||||||
*/
|
*/
|
||||||
const [mapDialog, setMapDialog] = useState<{ regionName: string | null } | null>(null);
|
const [mapRegionPickerOpen, setMapRegionPickerOpen] = useState(false);
|
||||||
|
|
||||||
const requestMapForAddressRegion = useCallback(() => {
|
const requestMapForAddressRegion = useCallback(() => {
|
||||||
Keyboard.dismiss();
|
Keyboard.dismiss();
|
||||||
setMapCenter(mapRegion?.center ?? null);
|
setMapRegionPickerOpen(true);
|
||||||
setMapDialog({ regionName: mapRegion?.name ?? null });
|
}, []);
|
||||||
}, [mapRegion]);
|
|
||||||
|
|
||||||
// The City selector's fallback: no town picked, so open the map straight away,
|
// Picked a region in that list: open the map focused on its bound.
|
||||||
// focused on the first region's bound (the first row of that selector).
|
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 openMapForFirstRegion = useCallback(() => {
|
||||||
const firstRegion = regions[0] ?? null;
|
const firstRegion = regions[0] ?? null;
|
||||||
setCityOpen(false);
|
setCityOpen(false);
|
||||||
|
setMapRegionPickerOpen(false);
|
||||||
setMapCenter(firstRegion?.center ?? null);
|
setMapCenter(firstRegion?.center ?? null);
|
||||||
setMapOpen(true);
|
setMapOpen(true);
|
||||||
}, [regions]);
|
}, [regions]);
|
||||||
|
|
||||||
const confirmMapDialog = useCallback(() => {
|
|
||||||
setMapDialog(null);
|
|
||||||
setMapOpen(true);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const dismissMapDialog = useCallback(() => {
|
|
||||||
setMapDialog(null);
|
|
||||||
setMapCenter(null);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const closeMap = useCallback(() => {
|
const closeMap = useCallback(() => {
|
||||||
setMapOpen(false);
|
setMapOpen(false);
|
||||||
setMapCenter(null);
|
setMapCenter(null);
|
||||||
|
|
@ -382,10 +376,9 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
||||||
<MyTouchableOpacity
|
<MyTouchableOpacity
|
||||||
testID="address-city-option-map"
|
testID="address-city-option-map"
|
||||||
onPress={openMapForFirstRegion}
|
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-gray-800`}>Select in Map</MyText>
|
||||||
<MyText style={tw`text-blue-500 font-medium ml-2`}>Select in Map</MyText>
|
|
||||||
</MyTouchableOpacity>
|
</MyTouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
|
|
@ -480,43 +473,56 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
||||||
message={isEdit ? "Updating address..." : "Adding address..."}
|
message={isEdit ? "Updating address..." : "Adding address..."}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Confirm the region before handing over to the map WebView, which opens
|
{/* Region picker: the map opens focused on whichever region is chosen. */}
|
||||||
focused on that region's centre. ("Select in Map" skips this.) */}
|
<BottomDialog open={mapRegionPickerOpen} onClose={closeMapRegionPicker}>
|
||||||
<BottomDialog open={mapDialog !== null} onClose={dismissMapDialog}>
|
|
||||||
<View style={tw`p-6`}>
|
<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`}>
|
<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" />
|
<MaterialIcons name="map" size={20} color="#2563EB" />
|
||||||
</View>
|
</View>
|
||||||
<MyText style={tw`text-lg font-bold text-gray-900 flex-1`}>
|
<MyText style={tw`text-lg font-bold text-gray-900 flex-1`}>Select a region</MyText>
|
||||||
{mapDialog?.regionName
|
|
||||||
? `Open the map for ${mapDialog.regionName}?`
|
|
||||||
: 'Open the map?'}
|
|
||||||
</MyText>
|
|
||||||
</View>
|
</View>
|
||||||
|
<MyText style={tw`text-gray-500 text-sm mb-4`}>
|
||||||
<MyText style={tw`text-gray-600 text-sm`}>
|
The map opens on the region you pick.
|
||||||
{mapDialog?.regionName
|
|
||||||
? `The map will open on ${mapDialog.regionName}. Pick a point inside this region.`
|
|
||||||
: 'Pick a point on the map.'}
|
|
||||||
</MyText>
|
</MyText>
|
||||||
|
|
||||||
<View style={tw`flex-row gap-3 mt-6`}>
|
{regions.map((region) => (
|
||||||
<MyTouchableOpacity
|
<MyTouchableOpacity
|
||||||
testID="address-map-confirm-cancel"
|
key={region.id}
|
||||||
onPress={dismissMapDialog}
|
testID={`address-map-region-${region.id}`}
|
||||||
style={tw`flex-1 border border-gray-200 py-3.5 rounded-xl items-center`}
|
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>
|
||||||
<MyTouchableOpacity
|
))}
|
||||||
testID="address-map-confirm-open"
|
|
||||||
onPress={confirmMapDialog}
|
{regions.length === 0 && (
|
||||||
style={tw`flex-1 bg-brand500 py-3.5 rounded-xl items-center`}
|
<MyText style={tw`text-gray-400 text-sm py-3`}>No regions available</MyText>
|
||||||
>
|
)}
|
||||||
<MyText style={tw`text-white font-bold`}>Open map</MyText>
|
|
||||||
</MyTouchableOpacity>
|
{/* After the regions: skip naming one and open the map on the first
|
||||||
</View>
|
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>
|
</View>
|
||||||
</BottomDialog>
|
</BottomDialog>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,13 @@ export const Route = createFileRoute('/location-selector')({
|
||||||
// Optional centre override (?lat=&lng=&zoom=) so the map can be opened for a
|
// Optional centre override (?lat=&lng=&zoom=) so the map can be opened for a
|
||||||
// specific region; defaults to the Mahabubnagar town centre.
|
// specific region; defaults to the Mahabubnagar town centre.
|
||||||
validateSearch: (search: Record<string, unknown>) => {
|
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 => {
|
const num = (value: unknown): number | undefined => {
|
||||||
|
if (typeof value === 'number') return Number.isFinite(value) ? value : undefined
|
||||||
if (typeof value !== 'string' || value.trim() === '') return undefined
|
if (typeof value !== 'string' || value.trim() === '') return undefined
|
||||||
const parsed = Number(value)
|
const parsed = Number(value)
|
||||||
return Number.isFinite(parsed) ? parsed : undefined
|
return Number.isFinite(parsed) ? parsed : undefined
|
||||||
|
|
|
||||||
|
|
@ -4791,3 +4791,44 @@ user-ui
|
||||||
the first region's bound and opens the map in the same step, skipping the dialog; the two
|
the first region's bound and opens the map in the same step, skipping the dialog; the two
|
||||||
location triggers still ask first.
|
location triggers still ask first.
|
||||||
No other file changed. No tests run.
|
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.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue