// Solutions.tsx import React, { useState, useEffect, useRef } from "react" import { useQuery, useQueryClient } from "@tanstack/react-query" import { Prism as SyntaxHighlighter } from "react-syntax-highlighter" import { dracula } from "react-syntax-highlighter/dist/esm/styles/prism" import ScreenshotQueue from "../components/Queue/ScreenshotQueue" import { ProblemStatementData } from "../types/solutions" import SolutionCommands from "../components/Solutions/SolutionCommands" import Debug from "./Debug" import { useToast } from "../contexts/toast" import { COMMAND_KEY } from "../utils/platform" export const ContentSection = ({ title, content, isLoading }: { title: string content: React.ReactNode isLoading: boolean }) => (

{title}

{isLoading ? (

Extracting problem statement...

) : (
{content}
)}
) const SolutionSection = ({ title, content, isLoading, currentLanguage }: { title: string content: React.ReactNode isLoading: boolean currentLanguage: string }) => { const [copied, setCopied] = useState(false) const copyToClipboard = () => { if (typeof content === "string") { navigator.clipboard.writeText(content).then(() => { setCopied(true) setTimeout(() => setCopied(false), 2000) }) } } return (

{title}

{isLoading ? (

Loading solutions...

) : (
{content as string}
)}
) } interface FollowUp { id: number question: string answer: string | null error?: string } const FollowUpSection = ({ design }: { design: string }) => { const [followUps, setFollowUps] = useState([]) const [question, setQuestion] = useState("") const latestFollowUpRef = useRef(null) const isAsking = followUps.some( (followUp) => followUp.answer === null && !followUp.error ) // Bring each new question into view so its answer appears right below it useEffect(() => { latestFollowUpRef.current?.scrollIntoView({ behavior: "smooth", block: "start" }) }, [followUps.length]) const askFollowUp = async () => { const trimmedQuestion = question.trim() if (!trimmedQuestion || isAsking) return const id = Date.now() // Failed follow-ups have no answer, so they don't go back to the model const history = followUps.flatMap((followUp) => followUp.answer ? [{ question: followUp.question, answer: followUp.answer }] : [] ) setFollowUps((current) => [ ...current, { id, question: trimmedQuestion, answer: null } ]) setQuestion("") let result: { success: boolean; data?: string; error?: string } try { result = await window.electronAPI.askFollowUp({ design, history, question: trimmedQuestion }) } catch (error) { console.error("Error asking follow-up:", error) result = { success: false } } setFollowUps((current) => current.map((followUp) => { if (followUp.id !== id) return followUp return result.success && result.data ? { ...followUp, answer: result.data } : { ...followUp, error: result.error || "Failed to answer the follow-up." } }) ) } return (

Follow-ups

{followUps.map((followUp, index) => (
{followUp.question}
{followUp.error ? (

{followUp.error}

) : followUp.answer === null ? (

Thinking...

) : ( {followUp.answer} )}
))}