import { createResource, For, JSX, ParentComponent, Show, useContext, VoidComponent } from 'solid-js'; import { Stop } from '../types'; import { renderLineTransportMode, renderLinePicto, ScrollingText, TransportModeWeights } from '../utils'; import { AppContextContext, AppContextStore } from "../appContext"; import { BusinessDataContext, BusinessDataStore } from "../businessData"; import { SearchContext, SearchStore } from "./searchStore"; import "./stopPanel.scss"; const StopRepr: VoidComponent<{ stop: Stop }> = (props) => { const fontSize: number = 40; const businessDataStore: BusinessDataStore | undefined = useContext(BusinessDataContext); if (businessDataStore === undefined) return
; const { getLine } = businessDataStore; const fetchLinesRepr = async (lineIds: string[]): Promise => { const reprs = []; for (const lineId of lineIds) { const line = await getLine(lineId); if (line !== undefined) { reprs.push(
{renderLineTransportMode(line)}
); reprs.push(renderLinePicto(line)); } } return reprs; } const [lineReprs] = createResource(props.stop.lines, fetchLinesRepr); return
{props.stop.name} {(line: JSX.Element) => line}
; } type ByTransportModeReprs = { mode: JSX.Element | undefined; lines: Record; } const StopAreaRepr: VoidComponent<{ stop: Stop }> = (props) => { const fontSize: number = 10; const businessDataStore: BusinessDataStore | undefined = useContext(BusinessDataContext); const appContextStore: AppContextStore | undefined = useContext(AppContextContext); const searchStore: SearchStore | undefined = useContext(SearchContext); if (businessDataStore === undefined || appContextStore === undefined || searchStore === undefined) return
; const { getLine } = businessDataStore; const { setDisplayedStops } = appContextStore; const { setHighlightedStop, resetHighlightedStop } = searchStore; const fetchLinesRepr = async (stop: Stop): Promise => { const lineIds = new Set(stop.lines); const stops = stop.stops; for (const stop of stops) { stop.lines.forEach(lineIds.add, lineIds); } const byModeReprs: Record = {}; for (const lineId of lineIds) { const line = await getLine(lineId); if (line !== undefined) { if (!(line.transportMode in byModeReprs)) { byModeReprs[line.transportMode] = { mode:
{renderLineTransportMode(line)}
, lines: {} }; } byModeReprs[line.transportMode].lines[line.shortName] = renderLinePicto(line); } } const sortedTransportModes = Object.keys(byModeReprs).sort((x, y) => TransportModeWeights[x] < TransportModeWeights[y] ? 1 : -1); return
{(transportMode) => { const reprs = byModeReprs[transportMode]; const lineNames = Object.keys(reprs.lines).sort((x, y) => x.localeCompare(y)); return <> {reprs.mode}
{(lineName) => reprs.lines[lineName]}
; }}
; } const [lineReprs] = createResource(props.stop, fetchLinesRepr); return
setDisplayedStops([props.stop])} onMouseEnter={() => setHighlightedStop(props.stop)} onMouseLeave={resetHighlightedStop} >
{lineReprs()}
; } export const StopsPanel: ParentComponent<{ stops: Stop[], show: boolean }> = (props) => { return
x.name.localeCompare(y.name))}> {(stop) => { return }> ; }}
; }