import React, { useState } from 'react'; import { faRedoAlt, faWrench } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import Button from 'components/ui/Button'; import { ErrorSolution } from '../../types'; import SolutionDescription from './SolutionDescription'; type Props = { solution: ErrorSolution; }; export default function SolutionRunner({ solution }: Props) { const [isRunningSolution, setIsRunningSolution] = useState(false); const [wasExecutionSuccessful, setWasExecutionSuccessful] = useState(null); async function executeSolution() { if (isRunningSolution) { return; } try { setIsRunningSolution(true); if (!solution.execute_endpoint) { return; } const response = await fetch(solution.execute_endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, body: JSON.stringify({ solution: solution.class, parameters: solution.run_parameters }), }); setWasExecutionSuccessful(response.status >= 200 && response.status < 300); } catch (error) { console.error(error); setWasExecutionSuccessful(false); } finally { setIsRunningSolution(false); } } function refresh(event: React.MouseEvent) { event.preventDefault(); location.reload(); } return ( <> {wasExecutionSuccessful === null && ( <> )} {wasExecutionSuccessful === true && (

The solution was executed successfully.
Refresh now

)} {wasExecutionSuccessful === false && ( <>

Something went wrong. Please try refreshing the page and try again.
Refresh now

)} ); }