From d291c4f0cbac4d8e875f0babc18e7c44d94a5426 Mon Sep 17 00:00:00 2001 From: Ben Brooks Date: Mon, 24 Mar 2025 21:02:26 -0700 Subject: [PATCH 1/3] Single bit of state to manage core modal --- src/components/search/SearchPane.svelte | 3 +- src/routes/+page.svelte | 47 +++++++------------------ 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/src/components/search/SearchPane.svelte b/src/components/search/SearchPane.svelte index e532c880..4acbaacc 100644 --- a/src/components/search/SearchPane.svelte +++ b/src/components/search/SearchPane.svelte @@ -108,6 +108,7 @@ window.dispatchEvent(event); } + // only gets called when going trip planner -> stops and stations, not vice versa function handleTabSwitch() { const event = new CustomEvent('tabSwitched'); window.dispatchEvent(event); @@ -198,7 +199,7 @@ - {#if env.PUBLIC_OTP_SERVER_URL} + {#if true} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index cc9053c4..ced73f8d 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -20,14 +20,12 @@ import { analyticsDistanceToStop } from '$lib/Analytics/plausibleUtils'; import SurveyLauncher from '$components/surveys/SurveyLauncher.svelte'; + let currentModal = $state(null); let stop = $state(); let selectedTrip = $state(null); let showRoute = $state(false); let selectedRoute = $state(null); let showRouteMap = $state(false); - let showAllRoutesModal = $state(false); - let showTripPlanModal = $state(false); - let showRouteModal = $state(); let mapProvider = $state(null); let currentIntervalId = null; let alert = $state(null); @@ -43,20 +41,10 @@ let currentUserLocation = $state($userLocation); - $effect(() => { - if (showRouteModal && showAllRoutesModal) { - showAllRoutesModal = false; - } - - if (showAllRoutesModal) { - showRouteModal = false; - } - }); - function handleStopMarkerSelect(stopData) { + currentModal = 'stop'; stop = stopData; pushState(`/stops/${stop.id}`); - showAllRoutesModal = false; loadSurveys(stop, getUserId()); if (currentHighlightedStopId !== null) { @@ -75,8 +63,7 @@ } function handleViewAllRoutes() { - showRouteModal = false; - showAllRoutesModal = true; + currentModal = 'allRoutes'; } function handleModalRouteClick(route) { @@ -84,7 +71,7 @@ detail: { route } }); window.dispatchEvent(customEvent); - showAllRoutesModal = false; + currentModal = null; } function closePane() { @@ -100,11 +87,9 @@ selectedTrip = null; selectedRoute = null; showRoute = false; - showRouteModal = false; - showAllRoutesModal = false; mapProvider.unHighlightMarker(currentHighlightedStopId); currentHighlightedStopId = null; - showTripPlanModal = false; + currentModal = null; } function tripSelected(event) { @@ -139,7 +124,7 @@ polylines = routeData.polylines; stops = routeData.stops; currentIntervalId = routeData.currentIntervalId; - showRouteModal = true; + currentModal = 'route'; analytics.reportRouteClicked(selectedRoute.id); } @@ -184,7 +169,7 @@ if (!tripItineraries) { console.error('No itineraries found', 404); } - showTripPlanModal = true; + currentModal = 'tripPlanner'; } onMount(() => { @@ -196,7 +181,7 @@ if (browser) { window.addEventListener('tabSwitched', () => { - showTripPlanModal = false; + currentModal = null; }); window.addEventListener('planTripTabClicked', () => { @@ -233,19 +218,13 @@
- {#if stop} + {#if currentModal === 'stop'} - {/if} - - {#if showRouteModal} + {:else if currentModal === 'route'} - {/if} - - {#if showAllRoutesModal} + {:else if currentModal === 'allRoutes'} - {/if} - - {#if showTripPlanModal} + {:else if currentModal === 'tripPlan'} + />} {/if}
From 6f5bc029edc489eefcfdf40285744409ce5390de Mon Sep 17 00:00:00 2001 From: Ben Brooks Date: Mon, 24 Mar 2025 21:03:54 -0700 Subject: [PATCH 2/3] Remove rogue changes --- src/components/search/SearchPane.svelte | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/search/SearchPane.svelte b/src/components/search/SearchPane.svelte index 4acbaacc..e532c880 100644 --- a/src/components/search/SearchPane.svelte +++ b/src/components/search/SearchPane.svelte @@ -108,7 +108,6 @@ window.dispatchEvent(event); } - // only gets called when going trip planner -> stops and stations, not vice versa function handleTabSwitch() { const event = new CustomEvent('tabSwitched'); window.dispatchEvent(event); @@ -199,7 +198,7 @@ - {#if true} + {#if env.PUBLIC_OTP_SERVER_URL} From 7cb61a7dcc825142e9cf7492d8293397c084427a Mon Sep 17 00:00:00 2001 From: Ben Brooks Date: Thu, 27 Mar 2025 16:58:41 -0700 Subject: [PATCH 3/3] Use enum, fix typo --- src/routes/+page.svelte | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index ced73f8d..d8d25867 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -41,8 +41,15 @@ let currentUserLocation = $state($userLocation); + const Modal = { + STOP: 'stop', + ROUTE: 'route', + ALL_ROUTES: 'allRoutes', + TRIP_PLANNER: 'tripPlanner' + }; + function handleStopMarkerSelect(stopData) { - currentModal = 'stop'; + currentModal = Modal.STOP; stop = stopData; pushState(`/stops/${stop.id}`); loadSurveys(stop, getUserId()); @@ -63,7 +70,7 @@ } function handleViewAllRoutes() { - currentModal = 'allRoutes'; + currentModal = Modal.ALL_ROUTES; } function handleModalRouteClick(route) { @@ -124,7 +131,7 @@ polylines = routeData.polylines; stops = routeData.stops; currentIntervalId = routeData.currentIntervalId; - currentModal = 'route'; + currentModal = Modal.ROUTE; analytics.reportRouteClicked(selectedRoute.id); } @@ -169,7 +176,7 @@ if (!tripItineraries) { console.error('No itineraries found', 404); } - currentModal = 'tripPlanner'; + currentModal = Modal.TRIP_PLANNER; } onMount(() => { @@ -218,13 +225,13 @@
- {#if currentModal === 'stop'} + {#if currentModal === Modal.STOP} - {:else if currentModal === 'route'} + {:else if currentModal === Modal.ROUTE} - {:else if currentModal === 'allRoutes'} + {:else if currentModal === Modal.ALL_ROUTES} - {:else if currentModal === 'tripPlan'} + {:else if currentModal === Modal.TRIP_PLANNER}