From e2134ad84af2ac1188a5b3c964c1f998f4a31ef8 Mon Sep 17 00:00:00 2001 From: neri Date: Wed, 11 Dec 2019 23:25:00 +0100 Subject: [PATCH] fetch actual room state --- src/pages/treff.js | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/pages/treff.js b/src/pages/treff.js index d0faa30..e2e5c9d 100644 --- a/src/pages/treff.js +++ b/src/pages/treff.js @@ -1,10 +1,26 @@ -import React from "react" +import React, { useEffect, useState } from "react" import Layout from "../components/layout" -export default () => ( - -

- Raumtatus OFFEN -

-
-) +export default () => { + const [opened, setOpened] = useState(false) + + useEffect(() => { + async function fetchState() { + const response = await fetch("https://status.ctdo.de/api/simple/v2") + const json = await response.json() + setOpened(json.state) + } + fetchState() + }, []) + + return ( + +

+ Raumtatus{" "} + + {opened ? "OFFEN" : "GESCHLOSSEN"} + +

+
+ ) +}