From 7294f35622abc6f2cbab4879501a369bb930e0de Mon Sep 17 00:00:00 2001 From: Adrien Date: Thu, 9 Feb 2023 22:36:42 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Filter=20old=20passages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only passages with a expectedDepartTs > now - 60s are kept. --- frontend/src/businessData.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/frontend/src/businessData.tsx b/frontend/src/businessData.tsx index c2e2388..07fb962 100644 --- a/frontend/src/businessData.tsx +++ b/frontend/src/businessData.tsx @@ -52,11 +52,29 @@ export function BusinessDataProvider(props: { children: JSX.Element }) { return store.passages; } + const _cleanupPassages = (passages: Passages): void => { + const deadline = Math.floor(Date.now() / 1000) - 60; + for (const linePassages of Object.values(passages)) { + for (const destination of Object.keys(linePassages)) { + const destinationPassages = linePassages[destination]; + const cleaned = []; + for (const passage of destinationPassages) { + if (passage.expectedDepartTs > deadline) { + cleaned.push(passage); + } + } + linePassages[destination] = cleaned; + + } + } + } + const refreshPassages = async (stopId: number): Promise => { const httpOptions = { headers: { "Content-Type": "application/json" } }; console.log(`Fetching data for ${stopId}`); const data = await fetch(`${serverUrl()}/stop/nextPassages/${stopId}`, httpOptions); const response = await data.json(); + _cleanupPassages(response.passages); addPassages(response.passages); }