diff --git a/frontend/src/businessData.tsx b/frontend/src/businessData.tsx index f1238eb..9699fb4 100644 --- a/frontend/src/businessData.tsx +++ b/frontend/src/businessData.tsx @@ -4,6 +4,8 @@ import { createStore } from 'solid-js/store'; import { Line, Lines, Passage, Passages, Stop, StopShape, StopShapes, Stops } from './types'; +export type StopDestinations = Record; + export interface BusinessDataStore { getLine: (lineId: string) => Promise; getLinePassages: (lineId: string) => Record; @@ -19,6 +21,7 @@ export interface BusinessDataStore { getStop: (stopId: number) => Stop | undefined; searchStopByName: (name: string) => Promise; + getStopDestinations: (stopId: number) => Promise; getStopShape: (stopId: number) => Promise; }; @@ -58,6 +61,7 @@ export function BusinessDataProvider(props: { children: JSX.Element }) { return Object.keys(store.passages[lineId]); } + // TODO: Remove this method: it's based on the next passages and return nothing until the refreshPassages is called. const getDestinationPassages = (lineId: string, destination: string): Passage[] => { return store.passages[lineId][destination]; } @@ -164,6 +168,14 @@ ${linePassagesDestination.length} here... refresh all them.`); return byIdStops; } + const getStopDestinations = async (stopId: number): Promise => { + const data = await fetch(`${serverUrl()}/stop/${stopId}/destinations`, { + headers: { 'Content-Type': 'application/json' } + }); + const response = await data.json(); + return response; + } + const getStopShape = async (stopId: number): Promise => { let shape = store.stopShapes[stopId]; if (shape === undefined) { @@ -180,7 +192,8 @@ ${linePassagesDestination.length} here... refresh all them.`); return ( {props.children}