Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent multiple location selections by locking the selection #121

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/components/trip-planner/TripPlan.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
let fromMarker;
let toMarker;
let loading = false;
let lockSelectLocation = false;

const dispatch = createEventDispatcher();

Expand Down Expand Up @@ -74,18 +75,25 @@
}

async function selectLocation(suggestion, isFrom) {
if (isFrom) {
const response = await geocodeLocation(suggestion.text);
selectedFrom = response.location.geometry.location;
fromMarker = mapProvider.addPinMarker(selectedFrom, 'From');
fromPlace = suggestion.text;
fromResults = [];
} else {
if (lockSelectLocation) return;
lockSelectLocation = true;
try {
const response = await geocodeLocation(suggestion.text);
selectedTo = response.location.geometry.location;
toMarker = mapProvider.addPinMarker(selectedTo, 'To');
toPlace = suggestion.text;
toResults = [];
if (isFrom) {
selectedFrom = response.location.geometry.location;
fromMarker = mapProvider.addPinMarker(selectedFrom, 'From');
fromPlace = suggestion.text;
fromResults = [];
} else {
selectedTo = response.location.geometry.location;
toMarker = mapProvider.addPinMarker(selectedTo, 'To');
toPlace = suggestion.text;
toResults = [];
}
} catch (error) {
console.error('Error selecting location:', error);
} finally {
lockSelectLocation = false;
}
}

Expand Down Expand Up @@ -147,7 +155,6 @@
}
}

// clear input fields when the tab is switched
onMount(() => {
if (browser) {
window.addEventListener('tabSwitched', () => {
Expand Down
Loading