fix confirmation dialog race condition
All checks were successful
pedestrian-simulator / build (push) Successful in 1m0s

This commit is contained in:
2026-01-13 14:03:34 -07:00
parent 41e82ed6e6
commit 12b1ad3b86

View File

@@ -120,79 +120,6 @@ function setupLoginHandler() {
});
}
// ...
// (Skipping to openKMLDetails implementation)
async function openKMLDetails(file) {
currentKmlFile = file;
const overlay = document.getElementById('kml-details-overlay');
// Reset UI
document.getElementById('kmlDetailsTitle').textContent = file.filename;
document.getElementById('kmlDetailsDistance').textContent = `📏 ${file.distance.toFixed(2)} km`;
document.getElementById('kmlDetailsAuthor').textContent = file.display_name ? `👤 ${file.display_name}` : '';
document.getElementById('kmlDetailsVotes').textContent = `👍 ${file.votes}`;
document.getElementById('kmlDescriptionDisplay').textContent = file.description || 'No description provided.';
// Show/Hide Edit Button (only for owner)
console.log(`[KML] Opening details. File Owner: ${file.user_id} (type: ${typeof file.user_id}), Current User: ${currentUserID} (type: ${typeof currentUserID})`);
if (file.user_id === currentUserID) {
document.getElementById('editDescriptionBtn').classList.remove('hidden');
} else {
document.getElementById('editDescriptionBtn').classList.add('hidden');
}
overlay.classList.add('active');
// Fetch and Parse KML
try {
const response = await fetch(`/api/kml/download?owner_id=${file.user_id}&filename=${encodeURIComponent(file.filename)}`);
if (!response.ok) throw new Error('Failed to download KML');
const kmlText = await response.text();
const parsed = parseKMLData(kmlText);
currentKmlPath = parsed.path;
currentKmlMarkers = parsed.markers;
// Render Map
if (!previewMap) {
previewMap = new google.maps.Map(document.getElementById('kmlPreviewMap'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
fullscreenControl: false,
streetViewControl: false
});
}
// Draw Route
if (previewPolyline) previewPolyline.setMap(null);
previewPolyline = new google.maps.Polyline({
path: currentKmlPath,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 4,
map: previewMap
});
const bounds = new google.maps.LatLngBounds();
currentKmlPath.forEach(pt => bounds.extend(pt));
previewMap.fitBounds(bounds);
} catch (err) {
console.error('Error loading KML details:', err);
alert('Failed to load route details.');
}
}
function setupLoginHandler() {
document.getElementById('fitbitLoginButton').addEventListener('click', () => {
window.location.href = '/auth/fitbit';
});
}
async function setupUserMenu() {
// This function could fetch user info and display it
// For now, the backend handles this via the Fitbit callback
@@ -214,9 +141,9 @@ async function setupUserMenu() {
// ========================================
function setupKMLBrowser() {
// Setup user menu
setupUserMenu();
setupKMLDetailsListeners();
setupUserProfileListeners();
// Tab switching
document.querySelectorAll('.kml-tab').forEach(tab => {
@@ -544,7 +471,11 @@ function setupKMLDetailsListeners() {
confirmText: 'Yes, Start New Trip',
isDanger: true
});
if (!confirmed) return;
console.log('[KML] Confirmation result:', confirmed);
if (!confirmed) {
console.log('[KML] Start new trip aborted by user');
return;
}
}
// Start the trip
@@ -880,7 +811,11 @@ function setupEventListeners() {
confirmText: 'Yes, Start New Trip',
isDanger: true
});
if (!confirmed) return;
console.log('[Manual] Confirmation result:', confirmed);
if (!confirmed) {
console.log('[Manual] Start new trip aborted by user');
return;
}
}
calculateAndStartRoute(startInput, endInput);
@@ -1157,10 +1092,6 @@ function startFromLocation(locationLatLng, address) {
// Start camera animation loop
startCameraAnimation();
// Initialize User Profile Listeners
setupUserProfileListeners();
setupKMLDetailsListeners();
// Check for Deep Links
restoreStateFromURL();
@@ -1168,7 +1099,9 @@ function startFromLocation(locationLatLng, address) {
}
function resetLocation() {
localStorage.removeItem(LOCATION_STORAGE);
// We don't remove LOCATION_STORAGE here anymore, so that the confirmation
// dialog in the Start buttons correctly sees the active trip.
// The storage will be overwritten when the NEW trip actually starts.
document.getElementById('setup-overlay').classList.add('active');
document.getElementById('startLocationInput').value = '';
document.getElementById('endLocationInput').value = '';