From d41853e0f2ab50a284267c3a086ff371d604cbaf Mon Sep 17 00:00:00 2001 From: Carter Date: Thu, 13 Nov 2025 10:55:46 -0600 Subject: [PATCH] fixed timestamp issue with displaying sen/temp/gas columns --- src/pages/Devices.tsx | 70 ++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/src/pages/Devices.tsx b/src/pages/Devices.tsx index 9f19d48..6617f9d 100644 --- a/src/pages/Devices.tsx +++ b/src/pages/Devices.tsx @@ -226,7 +226,7 @@ export default function Devices() { if (device.status.plenum?.timestamp) { const now = new Date(); const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000); - if (compareTimestamps(device.status.plenum?.timestamp, oneDayAgo.toISOString()) < 0) { + if (compareTimestamps(device.status.plenum?.timestamp, oneDayAgo.toISOString()) > 0) { return true } } else { @@ -241,13 +241,20 @@ export default function Devices() { if (device.status.sen5x?.timestamp) { const now = new Date(); const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000); - if (compareTimestamps(device.status.sen5x?.timestamp, oneDayAgo.toISOString()) < 0) { + if (compareTimestamps(device.status.sen5x?.timestamp, oneDayAgo.toISOString()) > 0) { + // console.log("timestamp success " + device.settings?.deviceId) return true - } + } else { + // console.log("timestamp fail " + device.settings?.deviceId) + } } else { + // console.log("no timestamp " + device.settings?.deviceId) return false } - } + } else { + // console.log("no temp and timestamp " + device.settings?.deviceId) + } + return false } @@ -261,7 +268,7 @@ export default function Devices() { if (device.status.sen5x?.timestamp) { const now = new Date(); const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000); - if (compareTimestamps(device.status.o2?.timestamp, oneDayAgo.toISOString()) < 0) { + if (compareTimestamps(device.status.o2?.timestamp, oneDayAgo.toISOString()) > 0) { return true } } else { @@ -276,7 +283,7 @@ export default function Devices() { if (device.status.co?.timestamp) { const now = new Date(); const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000); - if (compareTimestamps(device.status.co?.timestamp, oneDayAgo.toISOString()) < 0) { + if (compareTimestamps(device.status.co?.timestamp, oneDayAgo.toISOString()) > 0) { return true } } else { @@ -291,7 +298,7 @@ export default function Devices() { if (device.status.co2?.timestamp) { const now = new Date(); const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000); - if (compareTimestamps(device.status.co2?.timestamp, oneDayAgo.toISOString()) < 0) { + if (compareTimestamps(device.status.co2?.timestamp, oneDayAgo.toISOString()) > 0) { return true } } else { @@ -306,7 +313,7 @@ export default function Devices() { if (device.status.no2?.timestamp) { const now = new Date(); const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000); - if (compareTimestamps(device.status.no2?.timestamp, oneDayAgo.toISOString()) < 0) { + if (compareTimestamps(device.status.no2?.timestamp, oneDayAgo.toISOString()) > 0) { return true } } else { @@ -430,16 +437,29 @@ export default function Devices() { as ).then(resp => { let newDevices: Device[] = [] + let hasPlenum = false + let hasSen5x = false + let hasO2 = false + let hasCo = false + let hasCo2 = false + let hasNo2 = false resp.data.devices.forEach(device => { setHasPlenums(doesDeviceHavePlenum(device)) + if (doesDeviceHavePlenum(device)) hasPlenum = true // setHasPlenums(true) - setHasSen5x(doesDeviceHaveSen5x(device)) - setHasO2(doesDeviceHaveO2(device)) - setHasCo(doesDeviceHaveCo(device)) - setHasCo2(doesDeviceHaveCo2(device)) - setHasNo2(doesDeviceHaveNo2(device)) + if (doesDeviceHaveSen5x(device)) hasSen5x = true + if (doesDeviceHaveO2(device)) hasO2 = true + if (doesDeviceHaveCo(device)) hasCo = true + if (doesDeviceHaveCo2(device)) hasCo2 = true + if (doesDeviceHaveNo2(device)) hasNo2 = true newDevices.push(Device.create(device)) }) + setHasPlenums(hasPlenum) + setHasSen5x(hasSen5x) + setHasO2(hasO2) + setHasCo(hasCo) + setHasCo2(hasCo2) + setHasNo2(hasNo2) setDevices(newDevices) setTotal(resp.data.total) }).finally(() => { @@ -921,15 +941,29 @@ export default function Devices() { as ).then(resp => { let newDevices: Device[] = [] + let hasPlenum = false + let hasSen5x = false + let hasO2 = false + let hasCo = false + let hasCo2 = false + let hasNo2 = false resp.data.devices.forEach(device => { setHasPlenums(doesDeviceHavePlenum(device)) - setHasSen5x(doesDeviceHaveSen5x(device)) - setHasO2(doesDeviceHaveO2(device)) - setHasCo(doesDeviceHaveCo(device)) - setHasCo2(doesDeviceHaveCo2(device)) - setHasNo2(doesDeviceHaveNo2(device)) + if (doesDeviceHavePlenum(device)) hasPlenum = true + // setHasPlenums(true) + if (doesDeviceHaveSen5x(device)) hasSen5x = true + if (doesDeviceHaveO2(device)) hasO2 = true + if (doesDeviceHaveCo(device)) hasCo = true + if (doesDeviceHaveCo2(device)) hasCo2 = true + if (doesDeviceHaveNo2(device)) hasNo2 = true newDevices.push(Device.create(device)) }) + setHasPlenums(hasPlenum) + setHasSen5x(hasSen5x) + setHasO2(hasO2) + setHasCo(hasCo) + setHasCo2(hasCo2) + setHasNo2(hasNo2) setDevices(currentRows.concat(newDevices)) }).catch(_err => {