add 'loading' as initial room state
This commit is contained in:
parent
b9e37fea6c
commit
c63af48594
|
@ -1,14 +1,20 @@
|
||||||
import React, { useEffect, useState } from "react"
|
import React, { useEffect, useState } from "react"
|
||||||
import Layout from "../components/layout"
|
import Layout from "../components/layout"
|
||||||
|
|
||||||
|
const roomStateData = {
|
||||||
|
loading: { text: "lade…", color: "white" },
|
||||||
|
open: { text: "OFFEN", color: "forestgreen" },
|
||||||
|
closed: { text: "GESCHLOSSEN", color: "firebrick" },
|
||||||
|
}
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const [opened, setOpened] = useState(false)
|
const [openState, setOpenState] = useState("loading")
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchState() {
|
async function fetchState() {
|
||||||
const response = await fetch("https://status.ctdo.de/api/simple/v2")
|
const response = await fetch("https://status.ctdo.de/api/simple/v2")
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
setOpened(json.state)
|
setOpenState(json.state ? "open" : "closed")
|
||||||
}
|
}
|
||||||
fetchState()
|
fetchState()
|
||||||
}, [])
|
}, [])
|
||||||
|
@ -17,8 +23,8 @@ export default () => {
|
||||||
<Layout>
|
<Layout>
|
||||||
<h2>
|
<h2>
|
||||||
Raumstatus:{" "}
|
Raumstatus:{" "}
|
||||||
<span style={{ color: opened ? `forestgreen` : `firebrick` }}>
|
<span style={{ color: roomStateData[openState].color }}>
|
||||||
{opened ? "OFFEN" : "GESCHLOSSEN"}
|
{roomStateData[openState].text}
|
||||||
</span>
|
</span>
|
||||||
</h2>
|
</h2>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
Loading…
Reference in New Issue