+ {() => {
+ setPanels([]);
- // TODO: Sort transport modes by weight
- const Header: VoidComponent<{ passages: Passages, title: string }> = (props) => {
+ let newPanels = [];
+ let positioneds: PositionnedPanel[] = [];
+ let index = 0;
- const computeTransportModes = async (lineIds: string[]): Promise
=> {
- const lines = await Promise.all(lineIds.map((lineId) => getLine(lineId)));
- const urls: Set = new Set();
- for (const line of lines) {
- const src = getTransportModeSrc(line.transportMode, false);
- if (src !== undefined) {
- urls.add(src);
+ let chunk: Record> = {};
+ let chunkSize = 0;
+
+ for (const lineId of Object.keys(passages())) {
+ const byLinePassages = getLinePassages(lineId);
+ const byLinePassagesKeys = Object.keys(byLinePassages);
+
+ if (byLinePassagesKeys.length <= props.maxPassagesPerPanel - chunkSize) {
+ chunk[lineId] = byLinePassages;
+ chunkSize += byLinePassagesKeys.length;
+ }
+ else {
+ const panelid = index++;
+ const panel = ;
+ newPanels.push(panel);
+ positioneds.push({ position: panelid, panel: panel });
+
+ chunk = {};
+ chunk[lineId] = byLinePassages;
+ chunkSize = byLinePassagesKeys.length;
+ }
+ }
+ if (chunkSize) {
+ const panelId = index++;
+ const panel = ;
+ newPanels.push(panel);
+ positioneds.push({ position: panelId, panel: panel });
}
- }
- return Array.from(urls);
- }
- const [linesIds, setLinesIds] = createSignal([]);
- const [transportModeUrls] = createResource(linesIds, computeTransportModes);
+ setPanels(positioneds);
- createEffect(() => {
- setLinesIds(Object.keys(props.passages));
- });
+ return newPanels;
+ }}
+
+ );
+}
- return (
-
- );
- };
+export const PassagesDisplay: ParentComponent = () => {
- const Footer: VoidComponent<{ panels: PositionnedPanel[] }> = (props) => {
- return (
-
- );
- }
+ const MAX_PASSAGES_PER_PANEL = 5;
+
+ // TODO: Use props.
+ const syncPeriodMsec = 20 * 1000;
+ const panelSwitchPeriodMsec = 4 * 1000;
return (