From 091a63759bd496370430324dde54db8630282dd2 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Thu, 15 Feb 2024 19:48:26 +0100 Subject: [PATCH] Created the VersionContext.jsx --- .../contexts/Version/VersionContext.jsx | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 webui/src/common/contexts/Version/VersionContext.jsx diff --git a/webui/src/common/contexts/Version/VersionContext.jsx b/webui/src/common/contexts/Version/VersionContext.jsx new file mode 100644 index 0000000..d63605d --- /dev/null +++ b/webui/src/common/contexts/Version/VersionContext.jsx @@ -0,0 +1,32 @@ +import {createContext, useEffect, useState} from "react"; + +export const VersionContext = createContext({}); + +export const VersionProvider = ({children}) => { + + const [versions, setVersions] = useState(["1.20.1"]); + + const updateVersions = () => { + fetch("https://piston-meta.mojang.com/mc/game/version_manifest.json") + .then(res => res.json()) + .then(data => { + let versions = []; + data.versions.forEach(version => { + if (version.type === "release" && version.id.split(".")[1] > 8) + versions.push(version.id); + }); + versions.push("1.8.8"); + setVersions(versions); + }); + } + + useEffect(() => { + updateVersions(); + }, []); + + return ( + + {children} + + ); +} \ No newline at end of file