import React, { useState, useEffect } from 'react'; import './App.css'; function Setup({ status, onComplete }) { const [loadingData, setLoadingData] = useState(false); const [loginUrl, setLoginUrl] = useState(''); const [message, setMessage] = useState(''); const [manualCode, setManualCode] = useState(''); const [showManualCode, setShowManualCode] = useState(false); useEffect(() => { // Automatically handle the OAuth callback if the URL has ?code= const urlParams = new URLSearchParams(window.location.search); const code = urlParams.get('code'); if (code) { handleAuthCallback(code); } }, []); const handleAuthCallback = async (code) => { setMessage('Completing login...'); try { const resp = await fetch('http://localhost:8000/api/setup/auth/callback', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ code }) }); if (resp.ok) { setMessage('Login successful. Please ensure both steps are complete.'); } else { setMessage('Login failed. Please try again.'); } } catch (e) { setMessage('Error during login callback.'); } }; const downloadData = async () => { setLoadingData(true); setMessage('Downloading EVE Online static data (this may take a few minutes)...'); try { const resp = await fetch('http://localhost:8000/api/setup/data', { method: 'POST' }); if (resp.ok) { setMessage('Data downloaded successfully!'); } else { setMessage('Failed to download data.'); } } catch (e) { setMessage('Error downloading data.'); } setLoadingData(false); }; const fetchLoginUrl = async () => { try { const resp = await fetch('http://localhost:8000/api/setup/auth/url'); if (resp.ok) { const data = await resp.json(); window.open(data.url, '_blank'); setShowManualCode(true); } } catch (e) { setMessage('Failed to fetch login URL.'); } }; return (
Let's get your environment set up.
Data is ready!
) : ( )}Authenticated!
) : (After granting access, you might be redirected to a broken page (like `https://localhost/callback/...`).
Copy the `code=` part from the URL address bar and paste it below:
{message}
{status.data_ready && status.auth_ready && !status.backend_ready && (Setup is complete, but the EVE Haul backend process needs to be restarted to load the downloaded data.
Please go to your terminal, press `Ctrl+C` to stop the backend, and start it again.
This page will automatically launch EVE Haul when the backend is ready.