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 () => {
<Layout> const [opened, setOpened] = useState(false)
<h2>
Raumtatus <span style={{ color: `green` }}>OFFEN</span> useEffect(() => {
</h2> async function fetchState() {
</Layout> const response = await fetch("https://status.ctdo.de/api/simple/v2")
) const json = await response.json()
setOpened(json.state)
}
fetchState()
}, [])
return (
<Layout>
<h2>
Raumtatus{" "}
<span style={{ color: opened ? `green` : `darkred` }}>
{opened ? "OFFEN" : "GESCHLOSSEN"}
</span>
</h2>
</Layout>
)
}