ctucx.git: mqtt-webui

webui for mqtt, can be used to control/display data in mqtt-topics

commit 6ca202d045a168c37d55e10cd5d5257fe77959d9
parent a497f7106367e2edba398550c24d3f7b2b0900ab
Author: Leah (ctucx) <git@ctu.cx>
Date: Thu, 8 Dec 2022 09:59:38 +0100

cache webui-config locally
1 file changed, 19 insertions(+), 1 deletion(-)
M
src/webui.js
|
20
+++++++++++++++++++-
diff --git a/src/webui.js b/src/webui.js
@@ -36,7 +36,25 @@ const transformMessage = (input, meta) => {
 
 const getConfig = async () => {
 	const response = await fetch('/config.json');
-	return await response.json();
+
+	if (!response.ok) {
+		if (!localStorage.getItem('config')) {
+			return {
+				pages: [{
+					pageid: "mainpage",
+					pagetitle: "No Config!",
+					sections: []
+				}]
+			};
+		}
+
+		return JSON.parse(localStorage.getItem('config'));
+	}
+
+	const config = await response.json();
+	localStorage.setItem('config', JSON.stringify(config));
+
+	return config;
 };