Skip to content

fix: detour accuracy rewrite + station toggle#23

Merged
GeiserX merged 1 commit intomainfrom
fix/detour-accuracy-toggle
Apr 6, 2026
Merged

fix: detour accuracy rewrite + station toggle#23
GeiserX merged 1 commit intomainfrom
fix/detour-accuracy-toggle

Conversation

@GeiserX
Copy link
Copy Markdown
Owner

@GeiserX GeiserX commented Apr 6, 2026

Summary

  • Detour algorithm rewrite: Replaces dual Valhalla calls (detour + baseline) with a single call + proportional baseline from the original route duration. Uses 15% window with through-waypoints pinning highway segments before/after the station. Eliminates baseline routing errors that caused inflated detour times (e.g. Erla showing +32min instead of ~12min).
  • Station toggle: Clicking an already-selected station on the map or sidebar deselects it, clearing the leg preview. Previously required clicking the X button.
  • Visual highlighting: Selected station in the sidebar gets a blue ring highlight to indicate active state.
  • Caddy streaming: flush_interval -1 already applied to production Caddy config (not in this PR — server-side config).

Test plan

  • Route Sangüesa/Zaragoza → Murcia, verify Erla detour shows ~10-15 min (not 32)
  • Click a station on map → popup opens. Click same station → popup closes + leg clears
  • Click station in sidebar → flies to it + shows leg. Click again → deselects + clears leg
  • Selected station shows blue ring highlight in sidebar
  • Verify NDJSON streaming renders stations progressively (after Caddy fix)

Summary by CodeRabbit

  • New Features
    • Added station selection toggle—click a selected station to deselect it.
    • Enhanced visual highlighting for active stations in the search panel.
    • Improved detour calculation accuracy by incorporating route duration context.

Detour accuracy: replace dual Valhalla calls with single call + proportional
baseline estimated from the original route duration. Uses a 15% window with
through-waypoints pinning highway segments before/after the station.

Station toggle: clicking an already-selected station (map or sidebar) now
deselects it and clears the leg preview. Selected station gets a blue ring
highlight in the sidebar list.
@GeiserX GeiserX merged commit 878bc0e into main Apr 6, 2026
1 check passed
@GeiserX GeiserX deleted the fix/detour-accuracy-toggle branch April 6, 2026 22:25
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 6, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: aa458cc8-da1d-4fe4-957b-a75cf039307f

📥 Commits

Reviewing files that changed from the base of the PR and between 03cf66f and c918845.

📒 Files selected for processing (4)
  • src/app/api/route-detour/route.ts
  • src/components/home-client.tsx
  • src/components/map/station-layer.tsx
  • src/components/search/search-panel.tsx

📝 Walkthrough

Walkthrough

The pull request refactors the detour calculation logic in the route-detour API endpoint to use a single Valhalla call with baseline estimation instead of a two-call approach, and introduces a station selection toggle mechanism across map and search components. The endpoint now requires a routeDuration field in request validation.

Changes

Cohort / File(s) Summary
API Detour Calculation
src/app/api/route-detour/route.ts
Added routeDuration validation; changed from dual Valhalla calls to single via-waypoint call; replaced baseline duration calculation with proportional estimation (routeDuration * segFraction); increased exit/rejoin search window from 3% to 15%.
Station Selection Toggle
src/components/map/station-layer.tsx, src/components/search/search-panel.tsx
Implemented toggle behavior for station selection: clicking selected station deselects it; clicking unselected station selects it. Updated dependency arrays and button click handlers in both components.
Request Payload & Handler Propagation
src/components/home-client.tsx
Added routeDuration to /api/route-detour payload; propagated onSelectStation callback handler to MapView and SearchPanel components.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/detour-accuracy-toggle

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant