1 import axios from 'axios';
2 import React, { useCallback, useEffect, useState } from 'react';
3 import { Helmet } from 'react-helmet';
4 import { useParams } from 'react-router-dom';
6 import NotFound from './NotFound';
7 import Seed from '../components/alttp-seeds/Seed';
8 import ErrorBoundary from '../components/common/ErrorBoundary';
9 import ErrorMessage from '../components/common/ErrorMessage';
10 import Loading from '../components/common/Loading';
12 export const Component = () => {
13 const params = useParams();
14 const { hash } = params;
16 const [error, setError] = useState(null);
17 const [loading, setLoading] = useState(true);
18 const [patch, setPatch] = useState(null);
19 const [seed, setSeed] = useState(null);
21 const loadSeed = useCallback((hash, ctrl) => {
23 .get(`/api/alttp-seed/${hash}`, { signal: ctrl.signal })
27 setSeed(response.data);
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>
101 <title>{seed.hash}</title>
104 <Seed onRetry={retry} patch={patch} seed={seed} />