From b999a7335150a0b3f3ba08fbe7bfedf3ca2b9b7f Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Thu, 1 Jun 2023 19:41:45 +0200 Subject: [PATCH] Created the StatusContext.jsx --- .../common/contexts/Status/StatusContext.jsx | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 client/src/common/contexts/Status/StatusContext.jsx diff --git a/client/src/common/contexts/Status/StatusContext.jsx b/client/src/common/contexts/Status/StatusContext.jsx new file mode 100644 index 0000000..85d1f58 --- /dev/null +++ b/client/src/common/contexts/Status/StatusContext.jsx @@ -0,0 +1,29 @@ +import React, {createContext, useEffect, useState} from "react"; +import {jsonRequest} from "@/common/utils/RequestUtil"; + +export const StatusContext = createContext({}); + +export const StatusProvider = (props) => { + + const [backendAvailable, setBackendAvailable] = useState(true); + + const updateStatus = () => jsonRequest("").then(result => { + if (result?.status !== "ok") { + setBackendAvailable(false); + } else { + setBackendAvailable(true); + } + }); + + useEffect(() => { + updateStatus(); + const interval = setInterval(() => updateStatus(), 5000); + return () => clearInterval(interval); + }, []); + + return ( + + {props.children} + + ) +} \ No newline at end of file