⚡️ Reduce the refresh on passages update to the TtwPassage component
This commit is contained in:
@@ -202,7 +202,7 @@ const Body: ParentComponent<{ maxPassagesPerPanel: number, syncPeriodMsec: numbe
|
||||
return <div />;
|
||||
}
|
||||
|
||||
const { getLinePassages, passages, clearPassages, refreshPassages } = businessDataStore;
|
||||
const { getLinePassages, getLineDestinations, passages, getPassagesLineIds, clearPassages, refreshPassages } = businessDataStore;
|
||||
const { isPassagesRefreshEnabled, getDisplayedPanelId, setDisplayedPanelId, getPanels, setPanels } = passagesDisplayStore;
|
||||
const { getDisplayedStops } = searchStore;
|
||||
|
||||
@@ -253,31 +253,29 @@ const Body: ParentComponent<{ maxPassagesPerPanel: number, syncPeriodMsec: numbe
|
||||
let positioneds: PositionnedPanel[] = [];
|
||||
let index = 0;
|
||||
|
||||
let chunk: Record<string, Record<string, Passage[]>> = {};
|
||||
let chunkSize = 0;
|
||||
let lineIds: string[] = [];
|
||||
let destinationsNb = 0;
|
||||
|
||||
for (const lineId of Object.keys(passages())) {
|
||||
const byLinePassages = getLinePassages(lineId);
|
||||
const byLinePassagesKeys = Object.keys(byLinePassages);
|
||||
for (const lineId of getPassagesLineIds()) {
|
||||
const lineDestinations = getLineDestinations(lineId);
|
||||
|
||||
if (byLinePassagesKeys.length <= props.maxPassagesPerPanel - chunkSize) {
|
||||
chunk[lineId] = byLinePassages;
|
||||
chunkSize += byLinePassagesKeys.length;
|
||||
if (lineDestinations.length <= props.maxPassagesPerPanel - destinationsNb) {
|
||||
lineIds.push(lineId);
|
||||
destinationsNb += lineDestinations.length;
|
||||
}
|
||||
else {
|
||||
const panelid = index++;
|
||||
const panel = <PassagesPanel show={panelid == getDisplayedPanelId()} passages={chunk} />;
|
||||
const panel = <PassagesPanel stopId={getDisplayedStops()[0].id} lineIds={lineIds} show={panelid == getDisplayedPanelId()} />;
|
||||
newPanels.push(panel);
|
||||
positioneds.push({ position: panelid, panel: panel });
|
||||
|
||||
chunk = {};
|
||||
chunk[lineId] = byLinePassages;
|
||||
chunkSize = byLinePassagesKeys.length;
|
||||
lineIds = [lineId];
|
||||
destinationsNb = lineDestinations.length;
|
||||
}
|
||||
}
|
||||
if (chunkSize) {
|
||||
if (destinationsNb) {
|
||||
const panelId = index++;
|
||||
const panel = <PassagesPanel show={panelId == getDisplayedPanelId()} passages={chunk} />;
|
||||
const panel = <PassagesPanel stopId={getDisplayedStops()[0].id} lineIds={lineIds} show={panelId == getDisplayedPanelId()} />;
|
||||
newPanels.push(panel);
|
||||
positioneds.push({ position: panelId, panel: panel });
|
||||
}
|
||||
|
Reference in New Issue
Block a user