From f4443b8ccf7e3c5c1a619af031e4f03608b04a14 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Wed, 17 Jul 2024 21:29:57 +0300 Subject: [PATCH 1/6] Improve error handling since the API seem to be a acting up https://nextjs.org/docs/pages/building-your-application/data-fetching/incremental-static-regeneration#error-handling-and-revalidation --- src/pages/air/city/[id].js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pages/air/city/[id].js b/src/pages/air/city/[id].js index 65f407e8..fa69f2f3 100644 --- a/src/pages/air/city/[id].js +++ b/src/pages/air/city/[id].js @@ -291,9 +291,10 @@ export async function getStaticProps({ params: { id: city } }) { const airRes = await API.getAirData(city); const weeklyP2Res = await API.getWeeklyP2Data(city); if (!(airRes.ok || weeklyP2Res.ok)) { - return { - notFound: true, - }; + // Throw an error instead of returning so that the cache is not updated + // until the next successful request. + const status = `air: ${airRes.status}, weeklyP2: ${weeklyP2Res.status}`; + throw new Error(`Failed to fetch data, received status ${status}`); } const air = (await airRes.json()) || {}; const weeklyP2 = (await weeklyP2Res.json()) || {}; From 513168bcf0fb96eedd50c6625172ca67aba4b6c4 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Wed, 17 Jul 2024 21:34:23 +0300 Subject: [PATCH 2/6] Revalidate at 5 mins interval --- src/pages/air/city/[id].js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/air/city/[id].js b/src/pages/air/city/[id].js index fa69f2f3..97e44a7c 100644 --- a/src/pages/air/city/[id].js +++ b/src/pages/air/city/[id].js @@ -299,7 +299,11 @@ export async function getStaticProps({ params: { id: city } }) { const air = (await airRes.json()) || {}; const weeklyP2 = (await weeklyP2Res.json()) || {}; const data = { air, weeklyP2 }; - return { props: { city, data }, revalidate: 5 * 60 * 60 }; + return { + props: { city, data }, + // API update data every 5 mins + revalidate: 5 * 60, // in seconds + }; } export default City; From a74a4ae80d11ba32a0e0a2a5762ace486ddfe581 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Wed, 17 Jul 2024 21:48:03 +0300 Subject: [PATCH 3/6] Handle cases where we don't have data --- src/api/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/api/index.js b/src/api/index.js index 975b0939..f11d1615 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -5,7 +5,8 @@ const P2_READING = "P2"; const formatAirStats = (data, isPm2 = false) => { const formatted = {}; ["average", "maximum", "minimum"].forEach((stat) => { - const parsed = Number.parseFloat(data[stat]); + // Handle cases we have not data + const parsed = Number.parseFloat(data?.[stat]); if (isPm2 && stat === "average") { formatted.averageDescription = `measurements not recorded`; if (!Number.isNaN(parsed)) { From 84dd8e3c2af1bec758e3db2fedd4c029febbcde3 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Wed, 17 Jul 2024 22:17:14 +0300 Subject: [PATCH 4/6] Darken Backdrop just a touch --- src/components/Hambuger/HambugerMenu.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/Hambuger/HambugerMenu.js b/src/components/Hambuger/HambugerMenu.js index 427f7710..2d73f532 100644 --- a/src/components/Hambuger/HambugerMenu.js +++ b/src/components/Hambuger/HambugerMenu.js @@ -56,6 +56,11 @@ function HambugerMenu({ handleToggle, menuOpen, ...props }) { Date: Wed, 17 Jul 2024 22:17:38 +0300 Subject: [PATCH 5/6] Define packageMaanger (and engines) --- package.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 58b25d4a..af7f638f 100644 --- a/package.json +++ b/package.json @@ -83,5 +83,10 @@ "*.yml": [ "yarn format-staged" ] - } + }, + "engines": { + "node": "20.x", + "yarn": "1" + }, + "packageManager": "yarn@1.22.22" } From 3abed703237081221e0f5b3de3de9642b9b2e4d1 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Thu, 18 Jul 2024 09:24:55 +0300 Subject: [PATCH 6/6] =?UTF-8?q?Bump=20version:=200.4.21=20=E2=86=92=200.4.?= =?UTF-8?q?22?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contrib/dokku/Dockerfile | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/dokku/Dockerfile b/contrib/dokku/Dockerfile index da67ed57..49448b72 100644 --- a/contrib/dokku/Dockerfile +++ b/contrib/dokku/Dockerfile @@ -1 +1 @@ -FROM codeforafrica/sensors-africa-ui:0.4.21 +FROM codeforafrica/sensors-africa-ui:0.4.22 diff --git a/package.json b/package.json index af7f638f..7736732b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sensors.africa", "description": "sensors.AFRICA", - "version": "0.4.21", + "version": "0.4.22", "private": true, "main": "index.js", "homepage": "https://sensors.africa/",