]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/pages/AosSeed.js
aos seed generation
[alttp.git] / resources / js / components / pages / AosSeed.js
index 6cea156640001c3228ac93c911db88c82a3eb11f..e3cfda8f93b6a8f3e6b754b6007691d1e0254eb3 100644 (file)
@@ -1,5 +1,5 @@
 import axios from 'axios';
-import React, { useEffect, useState } from 'react';
+import React, { useCallback, useEffect, useState } from 'react';
 import { useParams } from 'react-router-dom';
 
 import NotFound from './NotFound';
@@ -17,9 +17,7 @@ const AosSeed = () => {
        const [patch, setPatch] = useState(null);
        const [seed, setSeed] = useState(null);
 
-       useEffect(() => {
-               setLoading(true);
-               const ctrl = new AbortController();
+       const loadSeed = useCallback((hash, ctrl) => {
                axios
                        .get(`/api/aos-seed/${hash}`, { signal: ctrl.signal })
                        .then(response => {
@@ -33,13 +31,36 @@ const AosSeed = () => {
                                setLoading(false);
                                setSeed(null);
                        });
+       }, []);
+
+       useEffect(() => {
+               setLoading(true);
+               const ctrl = new AbortController();
+               loadSeed(hash, ctrl);
                return () => {
                        ctrl.abort();
                };
        }, [hash]);
 
+       useEffect(() => {
+               if (!seed || seed.status !== 'pending') {
+                       return;
+               }
+               const ctrl = new AbortController();
+               const timer = setTimeout(() => {
+                       loadSeed(seed.hash, ctrl);
+               }, 2000);
+               return () => {
+                       clearTimeout(timer);
+                       ctrl.abort();
+               };
+       }, [seed]);
+
        useEffect(() => {
                setPatch(null);
+               if (!seed || seed.status !== 'generated') {
+                       return;
+               }
                const ctrl = new AbortController();
                axios
                        .get(`/aos-seeds/${hash}.bps`, {
@@ -55,7 +76,7 @@ const AosSeed = () => {
                return () => {
                        ctrl.abort();
                };
-       }, [hash]);
+       }, [hash, seed]);
 
        if (loading) {
                return <Loading />;