fixed timestamp issue with displaying sen/temp/gas columns

This commit is contained in:
Carter 2025-11-13 10:55:46 -06:00
parent 181f1194e2
commit d41853e0f2

View file

@ -226,7 +226,7 @@ export default function Devices() {
if (device.status.plenum?.timestamp) { if (device.status.plenum?.timestamp) {
const now = new Date(); const now = new Date();
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000); 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 return true
} }
} else { } else {
@ -241,13 +241,20 @@ export default function Devices() {
if (device.status.sen5x?.timestamp) { if (device.status.sen5x?.timestamp) {
const now = new Date(); const now = new Date();
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000); 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 return true
} } else {
// console.log("timestamp fail " + device.settings?.deviceId)
}
} else { } else {
// console.log("no timestamp " + device.settings?.deviceId)
return false return false
} }
} } else {
// console.log("no temp and timestamp " + device.settings?.deviceId)
}
return false return false
} }
@ -261,7 +268,7 @@ export default function Devices() {
if (device.status.sen5x?.timestamp) { if (device.status.sen5x?.timestamp) {
const now = new Date(); const now = new Date();
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000); 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 return true
} }
} else { } else {
@ -276,7 +283,7 @@ export default function Devices() {
if (device.status.co?.timestamp) { if (device.status.co?.timestamp) {
const now = new Date(); const now = new Date();
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000); 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 return true
} }
} else { } else {
@ -291,7 +298,7 @@ export default function Devices() {
if (device.status.co2?.timestamp) { if (device.status.co2?.timestamp) {
const now = new Date(); const now = new Date();
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000); 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 return true
} }
} else { } else {
@ -306,7 +313,7 @@ export default function Devices() {
if (device.status.no2?.timestamp) { if (device.status.no2?.timestamp) {
const now = new Date(); const now = new Date();
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000); 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 return true
} }
} else { } else {
@ -430,16 +437,29 @@ export default function Devices() {
as as
).then(resp => { ).then(resp => {
let newDevices: Device[] = [] 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 => { resp.data.devices.forEach(device => {
setHasPlenums(doesDeviceHavePlenum(device)) setHasPlenums(doesDeviceHavePlenum(device))
if (doesDeviceHavePlenum(device)) hasPlenum = true
// setHasPlenums(true) // setHasPlenums(true)
setHasSen5x(doesDeviceHaveSen5x(device)) if (doesDeviceHaveSen5x(device)) hasSen5x = true
setHasO2(doesDeviceHaveO2(device)) if (doesDeviceHaveO2(device)) hasO2 = true
setHasCo(doesDeviceHaveCo(device)) if (doesDeviceHaveCo(device)) hasCo = true
setHasCo2(doesDeviceHaveCo2(device)) if (doesDeviceHaveCo2(device)) hasCo2 = true
setHasNo2(doesDeviceHaveNo2(device)) if (doesDeviceHaveNo2(device)) hasNo2 = true
newDevices.push(Device.create(device)) newDevices.push(Device.create(device))
}) })
setHasPlenums(hasPlenum)
setHasSen5x(hasSen5x)
setHasO2(hasO2)
setHasCo(hasCo)
setHasCo2(hasCo2)
setHasNo2(hasNo2)
setDevices(newDevices) setDevices(newDevices)
setTotal(resp.data.total) setTotal(resp.data.total)
}).finally(() => { }).finally(() => {
@ -921,15 +941,29 @@ export default function Devices() {
as as
).then(resp => { ).then(resp => {
let newDevices: Device[] = [] 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 => { resp.data.devices.forEach(device => {
setHasPlenums(doesDeviceHavePlenum(device)) setHasPlenums(doesDeviceHavePlenum(device))
setHasSen5x(doesDeviceHaveSen5x(device)) if (doesDeviceHavePlenum(device)) hasPlenum = true
setHasO2(doesDeviceHaveO2(device)) // setHasPlenums(true)
setHasCo(doesDeviceHaveCo(device)) if (doesDeviceHaveSen5x(device)) hasSen5x = true
setHasCo2(doesDeviceHaveCo2(device)) if (doesDeviceHaveO2(device)) hasO2 = true
setHasNo2(doesDeviceHaveNo2(device)) if (doesDeviceHaveCo(device)) hasCo = true
if (doesDeviceHaveCo2(device)) hasCo2 = true
if (doesDeviceHaveNo2(device)) hasNo2 = true
newDevices.push(Device.create(device)) newDevices.push(Device.create(device))
}) })
setHasPlenums(hasPlenum)
setHasSen5x(hasSen5x)
setHasO2(hasO2)
setHasCo(hasCo)
setHasCo2(hasCo2)
setHasNo2(hasNo2)
setDevices(currentRows.concat(newDevices)) setDevices(currentRows.concat(newDevices))
}).catch(_err => { }).catch(_err => {