add check device status

This commit is contained in:
Muhammad Izza Alfiansyah 2024-05-03 13:25:41 +07:00
parent e0d43f62b6
commit c9789cd61c
1 changed files with 26 additions and 0 deletions

View File

@ -77,8 +77,34 @@ export default function (props: JSX.HTMLAttributes<HTMLDivElement>) {
await deleteAllData(); await deleteAllData();
}; };
const checkStatusDevice = async () => {
const lastData1: any = await new Promise(async (res, rej) => {
const { data } = await supabase
.from("kondisi_tapai")
.select("created_time")
.order("created_time", { ascending: false })
.limit(1);
setTimeout(() => {
res(data);
}, 5000);
});
const { data: lastData2 } = await supabase
.from("kondisi_tapai")
.select("created_time")
.order("created_time", { ascending: false })
.limit(1);
if (lastData1![0].created_time == lastData2![0].created_time) {
alert("Device offline!");
}
await checkStatusDevice();
};
onMount(async () => { onMount(async () => {
await getLastHistori(); await getLastHistori();
await checkStatusDevice();
}); });
return ( return (