From a1f4df737d040118fc1446a6cd3277e8551cdfbf Mon Sep 17 00:00:00 2001 From: Muhammad Izza Alfiansyah Date: Sun, 30 Jun 2024 14:58:30 +0700 Subject: [PATCH] add realtimedata to app.tsx & pages/index.tsx --- website/src/App.tsx | 27 +++++++++++++++++++------ website/src/pages/Index.tsx | 39 +++++++++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/website/src/App.tsx b/website/src/App.tsx index c97bd60..4157f2c 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -103,20 +103,35 @@ export default function (props: JSX.HTMLAttributes) { if (!lastHistori()) { const lastData1: any = await new Promise(async (res) => { const { data } = await supabase - .from("kondisi_tapai") + .from("realtime_data") .select("created_time") - .order("created_time", { ascending: false }) - .limit(1); + .eq("id", 1); setTimeout(() => { res(data); }, 10000); }); const { data: lastData2 } = await supabase - .from("kondisi_tapai") + .from("realtime_data") .select("created_time") - .order("created_time", { ascending: false }) - .limit(1); + .eq("id", 1); + + // const lastData1: any = await new Promise(async (res) => { + // const { data } = await supabase + // .from("kondisi_tapai") + // .select("created_time") + // .order("created_time", { ascending: false }) + // .limit(1); + // setTimeout(() => { + // res(data); + // }, 10000); + // }); + + // const { data: lastData2 } = await supabase + // .from("kondisi_tapai") + // .select("created_time") + // .order("created_time", { ascending: false }) + // .limit(1); if (lastData1![0] == lastData2![0]) { alert("Device offline!"); diff --git a/website/src/pages/Index.tsx b/website/src/pages/Index.tsx index e2b32ee..65b0164 100644 --- a/website/src/pages/Index.tsx +++ b/website/src/pages/Index.tsx @@ -33,16 +33,16 @@ export default function () { const getData = async () => { const { data } = await supabase - .from("kondisi_tapai") + .from("realtime_data") .select("*") - .order("created_time", { ascending: false }) - .limit(10); + .eq("id", 1) + .limit(1); if (data != null && data.length > 0) { - const lastItem = data[0]; + const item = data[0]; - setSuhu(lastItem.suhu); - setKelembaban(lastItem.kelembaban); + setSuhu(item.suhu); + setKelembaban(item.kelembaban); setKadarGas([]); setTimeStamps([]); @@ -58,6 +58,33 @@ export default function () { }); }); } + + // const { data } = await supabase + // .from("kondisi_tapai") + // .select("*") + // .order("created_time", { ascending: false }) + // .limit(10); + + // if (data != null && data.length > 0) { + // const lastItem = data[0]; + + // setSuhu(lastItem.suhu); + // setKelembaban(lastItem.kelembaban); + // setKadarGas([]); + // setTimeStamps([]); + + // data.forEach((item) => { + // setKadarGas((val) => { + // val.push(item.kadar_gas.toString().slice(0, 4)); + // return val; + // }); + + // setTimeStamps((val) => { + // val.push(getTimes(item.created_time)); + // return val; + // }); + // }); + // } }; const renderChart = async () => {