feat: enhance LocationSearchMap and TransportationDetails components with initialization handling and airport mode logic

This commit is contained in:
Sean Morley
2026-01-09 13:10:27 -05:00
parent 12ff50ba1c
commit f4bf0a38bd
2 changed files with 85 additions and 43 deletions

View File

@@ -70,6 +70,7 @@
let searchTimeout: ReturnType<typeof setTimeout>;
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);

View File

@@ -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 @@
</div>
<!-- Start/End Codes -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div class="form-control">
<label class="label" for="start_code">
<span class="label-text font-medium"
>{$t('transportation.departure_code') || 'Departure code'}</span
>
</label>
<input
type="text"
id="start_code"
value={startCodeField}
on:input={handleStartCodeEvent}
class="input input-bordered bg-base-100/80 focus:bg-base-100 uppercase"
maxlength="5"
placeholder={airportMode ? 'JFK' : 'Code'}
/>
{#if transportation.type === 'plane' || airportMode}
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div class="form-control">
<label class="label" for="start_code">
<span class="label-text font-medium"
>{$t('transportation.departure_code') || 'Departure code'}</span
>
</label>
<input
type="text"
id="start_code"
value={startCodeField}
on:input={handleStartCodeEvent}
class="input input-bordered bg-base-100/80 focus:bg-base-100 uppercase"
maxlength="5"
placeholder={airportMode ? 'JFK' : 'Code'}
/>
</div>
<div class="form-control">
<label class="label" for="end_code">
<span class="label-text font-medium"
>{$t('transportation.arrival_code') || 'Arrival code'}</span
>
</label>
<input
type="text"
id="end_code"
value={endCodeField}
on:input={handleEndCodeEvent}
class="input input-bordered bg-base-100/80 focus:bg-base-100 uppercase"
maxlength="5"
placeholder={airportMode ? 'LHR' : 'Code'}
/>
</div>
</div>
<div class="form-control">
<label class="label" for="end_code">
<span class="label-text font-medium"
>{$t('transportation.arrival_code') || 'Arrival code'}</span
>
</label>
<input
type="text"
id="end_code"
value={endCodeField}
on:input={handleEndCodeEvent}
class="input input-bordered bg-base-100/80 focus:bg-base-100 uppercase"
maxlength="5"
placeholder={airportMode ? 'LHR' : 'Code'}
/>
</div>
</div>
{/if}
<!-- Rating Field -->
<div class="form-control">