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