Skip to content
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
52 changes: 19 additions & 33 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -43,20 +41,17 @@

let currentUserLocation = $state($userLocation);

$effect(() => {
if (showRouteModal && showAllRoutesModal) {
showAllRoutesModal = false;
}

if (showAllRoutesModal) {
showRouteModal = false;
}
});
const Modal = {
STOP: 'stop',
ROUTE: 'route',
ALL_ROUTES: 'allRoutes',
TRIP_PLANNER: 'tripPlanner'
};

function handleStopMarkerSelect(stopData) {
currentModal = Modal.STOP;
stop = stopData;
pushState(`/stops/${stop.id}`);
showAllRoutesModal = false;
loadSurveys(stop, getUserId());

if (currentHighlightedStopId !== null) {
Expand All @@ -75,16 +70,15 @@
}

function handleViewAllRoutes() {
showRouteModal = false;
showAllRoutesModal = true;
currentModal = Modal.ALL_ROUTES;
}

function handleModalRouteClick(route) {
const customEvent = new CustomEvent('routeSelectedFromModal', {
detail: { route }
});
window.dispatchEvent(customEvent);
showAllRoutesModal = false;
currentModal = null;
}

function closePane() {
Expand All @@ -100,11 +94,9 @@
selectedTrip = null;
selectedRoute = null;
showRoute = false;
showRouteModal = false;
showAllRoutesModal = false;
mapProvider.unHighlightMarker(currentHighlightedStopId);
currentHighlightedStopId = null;
showTripPlanModal = false;
currentModal = null;
}

function tripSelected(event) {
Expand Down Expand Up @@ -139,7 +131,7 @@
polylines = routeData.polylines;
stops = routeData.stops;
currentIntervalId = routeData.currentIntervalId;
showRouteModal = true;
currentModal = Modal.ROUTE;
analytics.reportRouteClicked(selectedRoute.id);
}

Expand Down Expand Up @@ -184,7 +176,7 @@
if (!tripItineraries) {
console.error('No itineraries found', 404);
}
showTripPlanModal = true;
currentModal = Modal.TRIP_PLANNER;
}

onMount(() => {
Expand All @@ -196,7 +188,7 @@

if (browser) {
window.addEventListener('tabSwitched', () => {
showTripPlanModal = false;
currentModal = null;
});

window.addEventListener('planTripTabClicked', () => {
Expand Down Expand Up @@ -233,27 +225,21 @@
</SearchPane>

<div class="mt-4 flex-1">
{#if stop}
{#if currentModal === Modal.STOP}
<StopModal {closePane} {tripSelected} {handleUpdateRouteMap} {stop} />
{/if}

{#if showRouteModal}
{:else if currentModal === Modal.ROUTE}
<RouteModal {closePane} {mapProvider} {stops} {selectedRoute} />
{/if}

{#if showAllRoutesModal}
{:else if currentModal === Modal.ALL_ROUTES}
<ViewAllRoutesModal {closePane} {handleModalRouteClick} />
{/if}

{#if showTripPlanModal}
{:else if currentModal === Modal.TRIP_PLANNER}
<TripPlanModal
{mapProvider}
itineraries={tripItineraries}
{fromMarker}
{toMarker}
loading={loadingItineraries}
{closePane}
/>
/>}
{/if}
</div>
</div>
Expand Down