X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Fpages%2FAosSeed.js;fp=resources%2Fjs%2Fcomponents%2Fpages%2FAosSeed.js;h=6cea156640001c3228ac93c911db88c82a3eb11f;hb=75b3b5826c781e47b3db693fa6d3d17f67c79e56;hp=0000000000000000000000000000000000000000;hpb=8f8c68f00151100f2a2fa535492847ddb6b7029a;p=alttp.git diff --git a/resources/js/components/pages/AosSeed.js b/resources/js/components/pages/AosSeed.js new file mode 100644 index 0000000..6cea156 --- /dev/null +++ b/resources/js/components/pages/AosSeed.js @@ -0,0 +1,77 @@ +import axios from 'axios'; +import React, { useEffect, useState } from 'react'; +import { useParams } from 'react-router-dom'; + +import NotFound from './NotFound'; +import Seed from '../aos/Seed'; +import ErrorBoundary from '../common/ErrorBoundary'; +import ErrorMessage from '../common/ErrorMessage'; +import Loading from '../common/Loading'; + +const AosSeed = () => { + const params = useParams(); + const { hash } = params; + + const [error, setError] = useState(null); + const [loading, setLoading] = useState(true); + const [patch, setPatch] = useState(null); + const [seed, setSeed] = useState(null); + + useEffect(() => { + setLoading(true); + const ctrl = new AbortController(); + axios + .get(`/api/aos-seed/${hash}`, { signal: ctrl.signal }) + .then(response => { + setError(null); + setLoading(false); + setSeed(response.data); + window.document.title = response.data.hash; + }) + .catch(error => { + setError(error); + setLoading(false); + setSeed(null); + }); + return () => { + ctrl.abort(); + }; + }, [hash]); + + useEffect(() => { + setPatch(null); + const ctrl = new AbortController(); + axios + .get(`/aos-seeds/${hash}.bps`, { + responseType: 'arraybuffer', + signal: ctrl.signal, + }) + .then(response => { + setPatch(response.data); + }) + .catch(error => { + setError(error); + }); + return () => { + ctrl.abort(); + }; + }, [hash]); + + if (loading) { + return ; + } + + if (error) { + return ; + } + + if (!seed) { + return ; + } + + return + + ; +}; + +export default AosSeed;