fetch actual room state

This commit is contained in:
neri 2019-12-11 23:25:00 +01:00
parent b2c8d80796
commit e2134ad84a
1 changed files with 24 additions and 8 deletions

View File

@ -1,10 +1,26 @@
import React from "react" import React, { useEffect, useState } from "react"
import Layout from "../components/layout" import Layout from "../components/layout"
export default () => ( 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 (
<Layout> <Layout>
<h2> <h2>
Raumtatus <span style={{ color: `green` }}>OFFEN</span> Raumtatus{" "}
<span style={{ color: opened ? `green` : `darkred` }}>
{opened ? "OFFEN" : "GESCHLOSSEN"}
</span>
</h2> </h2>
</Layout> </Layout>
) )
}