From 8a87040ca8e169b65fb2e00972bde886c9151ea2 Mon Sep 17 00:00:00 2001 From: Andrew <74398819+AndrewDTR@users.noreply.github.com> Date: Fri, 18 Oct 2024 19:27:14 -0500 Subject: [PATCH] fix truth table --- src/components/DoorStatus.jsx | 41 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/components/DoorStatus.jsx b/src/components/DoorStatus.jsx index 5efab17..561e0b7 100644 --- a/src/components/DoorStatus.jsx +++ b/src/components/DoorStatus.jsx @@ -2,35 +2,34 @@ import React, { useState, useEffect } from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faDoorOpen, faDoorClosed } from "@fortawesome/free-solid-svg-icons"; -const fetchDoorStatus = async () => { - try { - const response = await fetch("https://doors.amoses.dev/door-status"); - const data = await response.json(); +const DoorStatus = () => { + const [isOpen, setIsOpen] = useState(null); - // determine if the UPL is open based on either door being "on" - const backDoor = data.find((door) => door.door === "back"); - const frontDoor = data.find((door) => door.door === "front"); - - if (backDoor?.status === "on" && frontDoor?.status === "on") { - setIsOpen(true); - } else if (backDoor?.status === "off" || frontDoor?.status === "off") { - setIsOpen(false); - } else { - setIsOpen(null); // Optionally handle unexpected cases - } - } catch (error) { - console.error("Error fetching door status:", error); - setIsOpen(undefined); - } + const fetchDoorStatus = async () => { + try { + const response = await fetch("https://doors.amoses.dev/door-status"); + const data = await response.json(); + // determine if the UPL is open + const backDoor = data.find((door) => door.door === "back"); + const frontDoor = data.find((door) => door.door === "front"); + if (backDoor?.status === "off" || frontDoor?.status === "off") { + setIsOpen(false); + } else if (backDoor?.status === "on" && frontDoor?.status === "on") { + setIsOpen(true); + } + } catch (error) { + console.error("Error fetching door status:", error); + setIsOpen(undefined); + } + }; useEffect(() => { fetchDoorStatus(); const interval = setInterval(fetchDoorStatus, 10000); return () => clearInterval(interval); }, []); - return (