import { useState, useEffect } from 'react'; import { Card } from '../components/common/Card'; import { Button } from '../components/common/Button'; import { Download, FileText, Image, RefreshCw } from 'lucide-react'; import { apiClient } from '../api/client'; import { Study } from '../types'; export default function Results() { const [studies, setStudies] = useState([]); const [selectedStudyId, setSelectedStudyId] = useState(null); const [reportContent, setReportContent] = useState(null); const [loading, setLoading] = useState(false); useEffect(() => { apiClient.getStudies() .then(data => { setStudies(data.studies); if (data.studies.length > 0) { const completed = data.studies.find(s => s.status === 'completed'); setSelectedStudyId(completed?.id || data.studies[0].id); } }) .catch(console.error); }, []); useEffect(() => { if (selectedStudyId) { setLoading(true); apiClient.getStudyReport(selectedStudyId) .then(data => { setReportContent(data.content); setLoading(false); }) .catch(err => { console.error('Failed to fetch report:', err); // Fallback for demo if report doesn't exist setReportContent(`# Optimization Report: ${selectedStudyId} ## Executive Summary The optimization study successfully converged after 45 trials. The best design achieved a mass reduction of 15% while maintaining all constraints. ## Key Findings - **Best Objective Value**: 115.185 Hz - **Critical Parameter**: Plate Thickness (sensitivity: 0.85) - **Constraint Margins**: All safety factors > 1.2 ## Recommendations Based on the results, we recommend proceeding with the design from Trial #45. Further refinement could be achieved by narrowing the bounds for 'thickness'. `); setLoading(false); }); } }, [selectedStudyId]); const handleRegenerate = () => { if (!selectedStudyId) return; setLoading(true); // In a real app, this would call an endpoint to trigger report generation setTimeout(() => { setLoading(false); }, 2000); }; return (

Results Viewer

Analyze completed optimization studies

{/* Sidebar - Study Selection */} {/* Main Content - Report Viewer */}

Optimization Report

{loading ? (
Loading report...
) : reportContent ? (
{/* Simple markdown rendering for now */} {reportContent.split('\n').map((line, i) => { if (line.startsWith('# ')) return

{line.substring(2)}

; if (line.startsWith('## ')) return

{line.substring(3)}

; if (line.startsWith('- ')) return
  • {line.substring(2)}
  • ; return

    {line}

    ; })}
    ) : (
    Select a study to view results
    )}
    ); }