Overview
TheResult component displays the calculated route as a list of human-readable instructions. It processes the route data to remove intermediate stops on the same transit branch and presents clear walking and transit instructions.
Props
Array of route points returned from the server. Each point contains stop information including
name, branch_id, latitude, and longitude.Route Point Structure
Each point in the route array has the following structure:The name of the stop or location
Identifier for the transit branch/line
Latitude coordinate of the stop
Longitude coordinate of the stop
Unique identifier for the stop
Helper Function
beautifyRoute
Removes intermediate stops that are on the same transit branch, keeping only the boarding and alighting stops.Array of route points to process
- Uses reduce to process points sequentially
- Adds each point to the result array
- If three consecutive points share the same
branch_id, removes the middle one - This eliminates unnecessary intermediate stops while preserving route structure
Component Logic
- Returns
nullif no route data is available - Processes the route through
beautifyRoute - Maps each point to a list item with alternating instructions:
- Even indices (0, 2, 4…): “Caminar hasta” (Walk to)
- Odd indices (1, 3, 5…): “Bajarse en” (Get off at)
- Combines the stop name with the branch identifier
- Renders as an unordered list
Instruction Pattern
The component alternates between two types of instructions:- Walk to: “Caminar hasta [Stop Name] del ramal #[Branch ID]”
- Get off at: “Bajarse en [Stop Name] del ramal #[Branch ID]”
- You walk to the first stop
- You get off at the next stop (after riding)
- You walk to the next transfer point
- And so on…
Usage Example
beautifyRoute since it’s an intermediate stop on branch 5.
Rendered Output
The component renders a simple unordered list:Empty State
If the route is empty, undefined, or has no items, the component returnsnull and renders nothing:
File Location
src/client/Result.jsx