diff --git a/frontend/src/lib/components/shared/LocationSearchMap.svelte b/frontend/src/lib/components/shared/LocationSearchMap.svelte index c07d9e39..55086216 100644 --- a/frontend/src/lib/components/shared/LocationSearchMap.svelte +++ b/frontend/src/lib/components/shared/LocationSearchMap.svelte @@ -70,6 +70,7 @@ let searchTimeout: ReturnType; let initialApplied = false; let initialTransportationApplied = false; + let isInitializing = false; // Track any provided codes (airport / station / etc) let startCode: string | null = null; @@ -131,6 +132,8 @@ } async function applyInitialTransportationLocations() { + isInitializing = true; + if (initialStartLocation) { selectedStartLocation = { name: initialStartLocation.name, @@ -147,11 +150,8 @@ startCode = null; startSearchQuery = initialStartLocation.location || initialStartLocation.name; } - await performDetailedReverseGeocode( - initialStartLocation.lat, - initialStartLocation.lng, - 'start' - ); + // Never perform reverse geocoding when we have initial location data + // to avoid overwriting airport names with generic locations } if (initialEndLocation) { @@ -169,11 +169,17 @@ endCode = null; endSearchQuery = initialEndLocation.location || initialEndLocation.name; } - await performDetailedReverseGeocode(initialEndLocation.lat, initialEndLocation.lng, 'end'); + // Never perform reverse geocoding when we have initial location data + // to avoid overwriting airport names with generic locations } updateMapBounds(); emitTransportationUpdate(); + + // Small delay to ensure all reactive updates complete before allowing searches + setTimeout(() => { + isInitializing = false; + }, 100); } async function searchLocations(query: string) { @@ -276,6 +282,7 @@ } function handleSearchInput() { + if (isInitializing) return; clearTimeout(searchTimeout); searchTimeout = setTimeout(() => { searchLocations(searchQuery); @@ -283,6 +290,7 @@ } function handleStartSearchInput() { + if (isInitializing) return; clearTimeout(startSearchTimeout); startSearchTimeout = setTimeout(() => { searchStartLocation(startSearchQuery); @@ -290,6 +298,7 @@ } function handleEndSearchInput() { + if (isInitializing) return; clearTimeout(endSearchTimeout); endSearchTimeout = setTimeout(() => { searchEndLocation(endSearchQuery); diff --git a/frontend/src/lib/components/transportation/TransportationDetails.svelte b/frontend/src/lib/components/transportation/TransportationDetails.svelte index 4fe1c88a..8034a6be 100644 --- a/frontend/src/lib/components/transportation/TransportationDetails.svelte +++ b/frontend/src/lib/components/transportation/TransportationDetails.svelte @@ -26,6 +26,7 @@ let isReverseGeocoding = false; let airportMode = false; + let previousTransportationType: string | null = null; let initialSelection: { name: string; @@ -141,6 +142,36 @@ return trimmed.slice(0, 5); } + function clearAirportCodes() { + startCodeField = ''; + endCodeField = ''; + transportation.start_code = null; + transportation.end_code = null; + } + + // Track previous airport mode to detect when user disables it + let prevAirportMode = airportMode; + $: if (prevAirportMode !== airportMode) { + prevAirportMode = airportMode; + // When airport mode is disabled, clear airport codes + if (!airportMode) { + clearAirportCodes(); + } + } + + // Auto-enable airport mode only when transportation type CHANGES to plane + // Do not continuously re-enable - respect user's manual toggle + $: if ( + transportation.type === 'plane' && + previousTransportationType !== 'plane' && + !airportMode + ) { + previousTransportationType = transportation.type; + airportMode = true; + } else if (transportation.type !== previousTransportationType) { + previousTransportationType = transportation.type; + } + // Reactive constraints $: constraintStartDate = allDay ? fullStartDate && fullStartDate.includes('T') @@ -161,15 +192,15 @@ ) { const { start, end } = event.detail; - // Update from location - transportation.from_location = start.location; + // Update from location - use name (e.g., "John F. Kennedy International Airport") not location (full address) + transportation.from_location = start.name; transportation.origin_latitude = start.lat; transportation.origin_longitude = start.lng; transportation.start_code = normalizeCode(start.code || ''); startCodeField = startCodeField || transportation.start_code || ''; - // Update to location - transportation.to_location = end.location; + // Update to location - use name (e.g., "Zurich Airport") not location (full address) + transportation.to_location = end.name; transportation.destination_latitude = end.lat; transportation.destination_longitude = end.lng; transportation.end_code = normalizeCode(end.code || ''); @@ -637,40 +668,42 @@ -
-
- - + {#if transportation.type === 'plane' || airportMode} +
+
+ + +
+
+ + +
-
- - -
-
+ {/if}