From 9073211c776ac5de30e0863bc1bd8271a33106ed Mon Sep 17 00:00:00 2001 From: Space Date: Mon, 7 Apr 2025 23:35:14 +0200 Subject: [PATCH] Add online status indicator with dynamic border styling in Index component --- app/routes/_index.tsx | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index 641d6cd..2a728f3 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -43,6 +43,36 @@ export async function loader() { export default function Index() { const { posts } = useLoaderData(); + const [status, setStatus] = useState(""); + const [border_status, setBorderStatus] = useState("border-gray-700"); + + useEffect(() => { + if (status === "online") { + setBorderStatus("border-green-500"); + } else if (status === "offline") { + setBorderStatus("border-red-500"); + } else if (status === "dnd") { + setBorderStatus("border-red-600"); + } else if (status === "idle") { + setBorderStatus("border-yellow-500"); + } else { + setBorderStatus("border-gray-700"); + } + }, [status]); + + useEffect(() => { + fetch( + "https://shsf-api.cottonfieldworkers.shop/api/exec/6/c084ec4a-1b20-491e-ab2e-67c5fa8881e6" + ) + .then((res) => res.json()) + .then((data) => { + setStatus(data.status); + }) + .catch((err) => { + console.error(err); + setStatus("offline"); + }); + }, []); return (
@@ -74,7 +104,9 @@ export default function Index() { Space online
-
+