1 import axios from 'axios';
2 import React, { useCallback, useEffect, useState } from 'react';
3 import { useParams } from 'react-router-dom';
5 import NotFound from './NotFound';
6 import Seed from '../alttp-seeds/Seed';
7 import ErrorBoundary from '../common/ErrorBoundary';
8 import ErrorMessage from '../common/ErrorMessage';
9 import Loading from '../common/Loading';
11 const AosSeed = () => {
12 const params = useParams();
13 const { hash } = params;
15 const [error, setError] = useState(null);
16 const [loading, setLoading] = useState(true);
17 const [patch, setPatch] = useState(null);
18 const [seed, setSeed] = useState(null);
20 const loadSeed = useCallback((hash, ctrl) => {
22 .get(`/api/alttp-seed/${hash}`, { signal: ctrl.signal })
26 setSeed(response.data);
27 window.document.title = response.data.hash;
38 const ctrl = new AbortController();
46 if (!seed || seed.status !== 'pending') {
49 const ctrl = new AbortController();
50 const timer = setTimeout(() => {
51 loadSeed(seed.hash, ctrl);
61 if (!seed || seed.status !== 'generated') {
64 const ctrl = new AbortController();
66 .get(`/alttp-seeds/${hash}.bps`, {
67 responseType: 'arraybuffer',
71 setPatch(response.data);
81 const retry = useCallback(async () => {
82 await axios.post(`/api/alttp-seed/${hash}/retry`);
83 setSeed(seed => ({ ...seed, status: 'pending' }));
91 return <ErrorMessage error={error} />;
98 return <ErrorBoundary>
99 <Seed onRetry={retry} patch={patch} seed={seed} />
103 export default AosSeed;