✨ Add StopDestinations to the frontend business data
This commit is contained in:
@@ -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<string, string[]>;
|
||||
|
||||
export interface BusinessDataStore {
|
||||
getLine: (lineId: string) => Promise<Line>;
|
||||
getLinePassages: (lineId: string) => Record<string, Passage[]>;
|
||||
@@ -19,6 +21,7 @@ export interface BusinessDataStore {
|
||||
getStop: (stopId: number) => Stop | undefined;
|
||||
searchStopByName: (name: string) => Promise<Stops>;
|
||||
|
||||
getStopDestinations: (stopId: number) => Promise<StopDestinations>;
|
||||
getStopShape: (stopId: number) => Promise<StopShape | undefined>;
|
||||
};
|
||||
|
||||
@@ -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<StopDestinations> => {
|
||||
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<StopShape | undefined> => {
|
||||
let shape = store.stopShapes[stopId];
|
||||
if (shape === undefined) {
|
||||
@@ -180,7 +192,8 @@ ${linePassagesDestination.length} here... refresh all them.`);
|
||||
return (
|
||||
<BusinessDataContext.Provider value={{
|
||||
getLine, getLinePassages, getLineDestinations, getDestinationPassages, passages, getPassagesLineIds,
|
||||
refreshPassages, addPassages, clearPassages, getStop, searchStopByName
|
||||
refreshPassages, addPassages, clearPassages,
|
||||
getStop, getStopDestinations, getStopShape, searchStopByName
|
||||
}}>
|
||||
{props.children}
|
||||
</BusinessDataContext.Provider>
|
||||
|
Reference in New Issue
Block a user