From 0712b88f7202257ed507975982890ed8349592da Mon Sep 17 00:00:00 2001 From: hodasemi Date: Thu, 21 Sep 2023 11:22:03 +0200 Subject: [PATCH] Trying to get a grasp from frontend --- resources/js/main.js | 47 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/resources/js/main.js b/resources/js/main.js index 73676fc..891a48e 100644 --- a/resources/js/main.js +++ b/resources/js/main.js @@ -1,11 +1,42 @@ -fetch("/devices", { - method: "GET" -}) - .then(response => { - const div = document.getElementById("main"); +window.onload = startup; - let json = response.json(); +async function startup() { + const response = await fetch( + "/devices", + { + method: "GET" + } + ); - console.log(json); + const div = document.getElementById("main"); + + let json = await response.json(); + + console.log(json); + + console.log(json["plugs"]); + + Object.keys(json).forEach(entry => { + console.log(entry); + + // const [group_name, devices] = entry; + + // let group_label = document.createElement('label'); + // group_label.innerText = group_name; + + // div.appendChild(group_label); + + // for (let i = 0; i < devices.length; i++) { + // let device_div = document.createElement('div'); + + // let dev_name = document.createElement('label'); + // dev_name.innerText = devices[i][0]; + + // device_div.appendChild(dev_name); + // div.appendChild(device_div); + // } }) - .catch(error => console.error(error)); \ No newline at end of file +} + + +