From 7dd91a4f4742305174620598c22de990d2bee080 Mon Sep 17 00:00:00 2001 From: Vencislav Atanasov Date: Wed, 10 Jan 2024 14:43:18 +0200 Subject: [PATCH] Hide temperature readings which are more outdated than 24 hours --- src/widgets/SensorReading/SensorReading.jsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/widgets/SensorReading/SensorReading.jsx b/src/widgets/SensorReading/SensorReading.jsx index 973d376..7cc7c04 100644 --- a/src/widgets/SensorReading/SensorReading.jsx +++ b/src/widgets/SensorReading/SensorReading.jsx @@ -24,10 +24,16 @@ const SensorReading = ({ const formattedTimestamp = formatDefault(lastUpdate) + ' (' + formatDistanceToNow(lastUpdate) + ')'; const unit = units[type]; const formattedValue = value.toFixed(unit[1]) + unit[0]; - const isCurrent = timestamp && Date.now() - timestamp <= 3_600_000; + const readingAge = Date.now() - timestamp; + const isCurrent = readingAge <= 3_600_000; + const isVisible = readingAge <= 86_400_000; // TODO: only for type === Temperature const thermometerState = thresholds.filter(threshold => threshold < value).length; + if (!isVisible) { + return null; + } + return (