From 28d041136844b0ee73c457aeb2e5cfdd7ea5e323 Mon Sep 17 00:00:00 2001 From: jejolare Date: Wed, 25 Sep 2024 21:56:00 +0700 Subject: [PATCH] add one-by-one chart loading --- src/pages/charts/index.tsx | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/pages/charts/index.tsx b/src/pages/charts/index.tsx index 33a1186..b76ca62 100644 --- a/src/pages/charts/index.tsx +++ b/src/pages/charts/index.tsx @@ -43,22 +43,26 @@ function Charts() { const chartPeriod = 7 * 24 * 60 * 60 * 1e3; const offset = +new Date() - chartPeriod; - await Promise.all(titles.map(async title => { - const result = await Utils.fetchChartInfo(title, offset); - if (title === "hash-rate") { - console.log("hash-rate", result); - } - console.log(result); - - if (!result) return; + const results: { title: string, data: ChartSeriesElem[][] }[] = []; - setChartsSeries(prev => ({ - ...prev, - [title]: result.map( + for (const title of titles) { + const result = await Utils.fetchChartInfo(title, offset); + console.log('data loaded:', title); + + if (!result) continue; + + results.push({ + title: title, + data: result.map( series => series.filter(e => e.x > offset - chartPeriod) - ) - })) - })); + ) + }); + } + + setChartsSeries(prev => ({ + ...prev, + ...Object.fromEntries(results.map(e => [e.title, e.data] as [string, ChartSeriesElem[][]] )) + })) setLoaded(true); }