diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-04-20 20:15:55 +0200 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-04-20 20:15:55 +0200 |
| commit | 3676b1d1d9216a676c7d5a40affa5b3256ca8df3 (patch) | |
| tree | efa63a0d21ae52e32e405fe7b4ce56b02d782e86 /src/pages/StopList.tsx | |
| parent | c86b4655f72c86362c064dd50bb701782b39e6eb (diff) | |
Refactor stop data handling with caching and custom names support
Diffstat (limited to 'src/pages/StopList.tsx')
| -rw-r--r-- | src/pages/StopList.tsx | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/pages/StopList.tsx b/src/pages/StopList.tsx index 449ae84..a2269ec 100644 --- a/src/pages/StopList.tsx +++ b/src/pages/StopList.tsx @@ -37,12 +37,16 @@ export function StopList() { }, [data]) const recentStops = useMemo(() => { - const recent = StopDataProvider.getRecent(); - - if (recent.length === 0) return null; - - return recent.map(stopId => data?.find(stop => stop.stopId === stopId) as Stop).reverse(); - }, [data]) + // no recent items if data not loaded + if (!data) return null; + const recentIds = StopDataProvider.getRecent(); + if (recentIds.length === 0) return null; + // map and filter out missing entries + const stopsList = recentIds + .map(id => data.find(stop => stop.stopId === id)) + .filter((s): s is Stop => Boolean(s)); + return stopsList.reverse(); + }, [data]); if (data === null) return <h1 className="page-title">Loading...</h1> |
