Spaces:
Running
Running
Download algospaced-ui/src/components/review/CodeStudioPanel.tsx from iamfebin/algospaced-dsa: direct link, hf CLI and curl.
- Browser
- Download file 32.2 kB
-
https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/review/CodeStudioPanel.tsx
- Command line
-
hf download hf://spaces/iamfebin/algospaced-dsa/algospaced-ui/src/components/review/CodeStudioPanel.tsx
-
curl -L -o CodeStudioPanel.tsx https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/review/CodeStudioPanel.tsx
32.2 kB
| import React, { useState, useRef, useEffect } from 'react'; | |
| import { | |
| ChevronDown, | |
| Sparkles, | |
| RotateCcw, | |
| Trash2, | |
| Play, | |
| RefreshCw, | |
| AlertTriangle, | |
| Check, | |
| CheckCircle2, | |
| XCircle, | |
| Save, | |
| Award, | |
| Info, | |
| FolderGit2, | |
| ExternalLink | |
| } from 'lucide-react'; | |
| import CodeMirror from '@uiw/react-codemirror'; | |
| import { codeStudioExtensions } from './codeEditorExtensions'; | |
| import type { SandboxRunResult } from '../../services/reviewService'; | |
| import type { AiEvaluationResult } from '../../types/reviewTypes'; | |
| const AVAILABLE_LANGUAGES = [ | |
| { id: 'python', name: 'Python', version: '3.14' } | |
| ] as const; | |
| const PythonLogo: React.FC<{ className?: string }> = ({ className = 'w-3.5 h-3.5' }) => ( | |
| <svg viewBox="0 0 128 128" className={className} xmlns="http://www.w3.org/2000/svg"> | |
| <path | |
| d="M63.454 4.018c-14.775 0-23.774 6.425-23.774 18.775v13.626h24.168v3.424H30.082C17.518 39.843 8 47.962 8 63.673c0 15.65 8.358 23.486 21.056 23.486h11.905v-16.89c0-13.064 11.233-24.113 24.331-24.113h23.773V32.793c0-11.83-9.988-19.775-23.773-19.775H63.454v-9zm-9.845 7.426a3.84 3.84 0 0 1 3.86 3.84 3.84 3.84 0 0 1-3.86 3.841 3.84 3.84 0 0 1-3.86-3.84 3.84 3.84 0 0 1 3.86-3.841z" | |
| fill="#387eb8" | |
| /> | |
| <path | |
| d="M64.546 123.982c14.775 0 23.774-6.425 23.774-18.775V91.581H64.152v-3.424h33.766c12.564 0 22.082-8.119 22.082-23.83 0-15.65-8.358-23.486-21.056-23.486H87.04v16.89c0 13.064-11.234 24.113-24.332 24.113H38.934v13.363c0 11.83 9.989 19.775 23.774 19.775h1.838v9zm9.845-7.426a3.84 3.84 0 0 1-3.86-3.84 3.84 3.84 0 0 1 3.86-3.841 3.84 3.84 0 0 1 3.86 3.84 3.84 3.84 0 0 1-3.86 3.841z" | |
| fill="#ffe052" | |
| /> | |
| </svg> | |
| ); | |
| interface CodeStudioPanelProps { | |
| mobileView: 'spec' | 'code' | 'ref'; | |
| isAutocompleteEnabled: boolean; | |
| onToggleAutocomplete: (enabled: boolean) => void; | |
| onResetStarterCode: () => void; | |
| code: string; | |
| onChangeCode: (code: string) => void; | |
| sandboxRunning: boolean; | |
| sandboxError: string | null; | |
| sandboxResults: SandboxRunResult | null; | |
| onRunSandbox: () => void; | |
| savingReference: boolean; | |
| savedRefSuccess: boolean; | |
| saveRefError: string | null; | |
| onSaveReference: () => void; | |
| aiLoading: boolean; | |
| aiError: string | null; | |
| aiResult: AiEvaluationResult | null; | |
| onAiEvaluation: () => void; | |
| optimalTime: string; | |
| optimalSpace: string; | |
| isNarrow?: boolean; | |
| onPushToGitHub?: () => void; | |
| pushingToGitHub?: boolean; | |
| githubPushedUrl?: string | null; | |
| githubPushError?: string | null; | |
| } | |
| export const CodeStudioPanel: React.FC<CodeStudioPanelProps> = ({ | |
| mobileView, | |
| isNarrow = false, | |
| isAutocompleteEnabled, | |
| onToggleAutocomplete, | |
| onResetStarterCode, | |
| code, | |
| onChangeCode, | |
| sandboxRunning, | |
| sandboxError, | |
| sandboxResults, | |
| onRunSandbox, | |
| savingReference, | |
| savedRefSuccess, | |
| saveRefError, | |
| onSaveReference, | |
| aiLoading, | |
| aiError, | |
| aiResult, | |
| onAiEvaluation, | |
| optimalTime, | |
| optimalSpace, | |
| onPushToGitHub, | |
| pushingToGitHub, | |
| githubPushedUrl, | |
| githubPushError | |
| }) => { | |
| const [selectedLanguage, setSelectedLanguage] = useState<'python'>('python'); | |
| const [isLangDropdownOpen, setIsLangDropdownOpen] = useState(false); | |
| const langDropdownRef = useRef<HTMLDivElement>(null); | |
| useEffect(() => { | |
| const handleClickOutside = (event: MouseEvent) => { | |
| if (langDropdownRef.current && !langDropdownRef.current.contains(event.target as Node)) { | |
| setIsLangDropdownOpen(false); | |
| } | |
| }; | |
| const handleKeyDown = (event: KeyboardEvent) => { | |
| if (event.key === 'Escape') { | |
| setIsLangDropdownOpen(false); | |
| } | |
| }; | |
| document.addEventListener('mousedown', handleClickOutside); | |
| document.addEventListener('keydown', handleKeyDown); | |
| return () => { | |
| document.removeEventListener('mousedown', handleClickOutside); | |
| document.removeEventListener('keydown', handleKeyDown); | |
| }; | |
| }, []); | |
| const currentLang = AVAILABLE_LANGUAGES.find((l) => l.id === selectedLanguage) ?? AVAILABLE_LANGUAGES[0]; | |
| return ( | |
| <div | |
| className={`w-full ${isNarrow ? 'flex flex-1' : 'lg:w-[51%] flex' | |
| } flex-col bg-[#fffdfa] overflow-y-auto no-scrollbar ${isNarrow && mobileView !== 'code' ? 'hidden' : 'flex' | |
| }`} | |
| > | |
| {/* Studio Toolbar */} | |
| <div className="shrink-0 bg-[#f7f5ed] border-b-2 border-ink-black p-2 sm:px-3 flex flex-wrap items-center justify-between gap-1.5 sm:gap-2"> | |
| {/* Left: Language Selector & Autocomplete */} | |
| <div className="flex items-center gap-1.5 sm:gap-2 flex-wrap"> | |
| {/* Language Selector Dropdown */} | |
| <div className="relative" ref={langDropdownRef}> | |
| <button | |
| type="button" | |
| onClick={() => setIsLangDropdownOpen((prev) => !prev)} | |
| className="h-7 px-2.5 bg-white hover:bg-slate-100 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none flex items-center gap-1.5 font-arcade text-[9px] font-bold text-ink-black cursor-pointer transition-all select-none" | |
| title="Select programming language" | |
| aria-expanded={isLangDropdownOpen} | |
| aria-haspopup="listbox" | |
| > | |
| <PythonLogo className="w-3.5 h-3.5 shrink-0" /> | |
| <span>{currentLang.name}</span> | |
| <ChevronDown className={`w-3 h-3 text-ink-black transition-transform duration-150 ${isLangDropdownOpen ? 'rotate-180' : ''}`} /> | |
| </button> | |
| {/* Dropdown Menu */} | |
| {isLangDropdownOpen && ( | |
| <div | |
| className="absolute top-full mt-1.5 left-0 z-50 w-52 bg-paper-white border-[3px] border-ink-black gadget-shadow p-1.5 space-y-1" | |
| role="listbox" | |
| > | |
| <div className="px-2 py-1 text-[8px] font-arcade font-bold text-trash-gray uppercase border-b border-slate-200"> | |
| SELECT LANGUAGE | |
| </div> | |
| {AVAILABLE_LANGUAGES.map((lang) => { | |
| const isSelected = selectedLanguage === lang.id; | |
| return ( | |
| <button | |
| key={lang.id} | |
| type="button" | |
| role="option" | |
| aria-selected={isSelected} | |
| onClick={() => { | |
| setSelectedLanguage(lang.id); | |
| setIsLangDropdownOpen(false); | |
| }} | |
| className={`w-full flex items-center justify-between px-2.5 py-1.5 border-2 border-ink-black text-left transition-all cursor-pointer ${isSelected | |
| ? 'bg-amber-200 shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] font-bold text-ink-black' | |
| : 'bg-white hover:bg-slate-100 text-slate-800' | |
| }`} | |
| > | |
| <div className="flex items-center gap-1.5 font-arcade text-[9px]"> | |
| <PythonLogo className="w-3.5 h-3.5 shrink-0" /> | |
| <span>{lang.name}</span> | |
| </div> | |
| <span className="font-mono text-[8px] font-bold px-1.5 py-0.5 bg-white border border-ink-black text-slate-700 shadow-[1px_1px_0px_0px_rgba(30,41,59,0.3)]"> | |
| v{lang.version} | |
| </span> | |
| </button> | |
| ); | |
| })} | |
| </div> | |
| )} | |
| </div> | |
| <div className="h-4 w-[2px] bg-slate-300 mx-0.5 hidden sm:block" /> | |
| {/* Autocomplete Toggle */} | |
| <label className="inline-flex items-center gap-1.5 cursor-pointer select-none"> | |
| <input | |
| type="checkbox" | |
| checked={isAutocompleteEnabled} | |
| onChange={(e) => onToggleAutocomplete(e.target.checked)} | |
| className="sr-only peer" | |
| aria-label="Toggle code editor autocompletion" | |
| /> | |
| <div className="relative w-7 h-3.5 bg-slate-300 border border-ink-black rounded-full peer peer-checked:bg-grass-green transition-all after:content-[''] after:absolute after:top-[1px] after:left-[2px] after:bg-white after:border after:border-ink-black after:rounded-full after:h-2 after:w-2 after:transition-all peer-checked:after:translate-x-3"></div> | |
| <span className="text-[7.5px] min-[400px]:text-[8px] font-arcade font-bold text-trash-gray peer-checked:text-ink-black whitespace-nowrap"> | |
| AUTOCOMPLETE | |
| </span> | |
| </label> | |
| </div> | |
| {/* Middle: Secondary Tools (Reset, Delete, Save, GitHub) */} | |
| <div className="flex items-center gap-1.5 sm:gap-2"> | |
| {/* Reset Starter Code */} | |
| <button | |
| onClick={onResetStarterCode} | |
| className="w-7 h-7 bg-white hover:bg-slate-100 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-ink-black flex items-center justify-center cursor-pointer transition-all" | |
| title="Reset to starter code" | |
| aria-label="Reset to starter code" | |
| > | |
| <RotateCcw className="w-3.5 h-3.5" /> | |
| </button> | |
| {/* Clear Editor */} | |
| <button | |
| onClick={() => onChangeCode('')} | |
| className="w-7 h-7 bg-white hover:bg-rose-50 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-rose-700 flex items-center justify-center cursor-pointer transition-all" | |
| title="Clear editor" | |
| aria-label="Clear editor" | |
| > | |
| <Trash2 className="w-3.5 h-3.5 text-rose-600" /> | |
| </button> | |
| {/* Overwrite / Save Solution with Studio Code */} | |
| {onSaveReference && ( | |
| <button | |
| onClick={onSaveReference} | |
| disabled={savingReference || !code.trim()} | |
| className={`w-7 h-7 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none flex items-center justify-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed transition-all ${savedRefSuccess | |
| ? 'bg-emerald-600 hover:bg-emerald-500 text-white' | |
| : 'bg-amber-400 hover:bg-amber-300 text-ink-black' | |
| }`} | |
| title={ | |
| savingReference | |
| ? 'Saving solution to personal database...' | |
| : savedRefSuccess | |
| ? 'Saved to personal database!' | |
| : 'Overwrite saved solution with studio code' | |
| } | |
| aria-label="Overwrite saved solution with studio code" | |
| > | |
| {savingReference ? ( | |
| <RefreshCw className="w-3.5 h-3.5 animate-spin text-ink-black" /> | |
| ) : savedRefSuccess ? ( | |
| <CheckCircle2 className="w-3.5 h-3.5 text-white" /> | |
| ) : ( | |
| <Save className="w-3.5 h-3.5 text-ink-black" /> | |
| )} | |
| </button> | |
| )} | |
| {/* Push to GitHub */} | |
| {onPushToGitHub && ( | |
| <button | |
| onClick={onPushToGitHub} | |
| disabled={pushingToGitHub || !code.trim()} | |
| className="w-7 h-7 bg-[#24292e] hover:bg-black border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-white flex items-center justify-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed transition-all" | |
| title={pushingToGitHub ? 'Pushing to GitHub...' : 'Push solution to GitHub repository'} | |
| aria-label="Push to GitHub" | |
| > | |
| {pushingToGitHub ? ( | |
| <RefreshCw className="w-3.5 h-3.5 animate-spin text-yellow-300" /> | |
| ) : ( | |
| <FolderGit2 className="w-3.5 h-3.5 text-yellow-300" /> | |
| )} | |
| </button> | |
| )} | |
| </div> | |
| {/* Right: Primary Actions (Run & Gemini Eval) */} | |
| <div className="flex items-center gap-1.5 sm:gap-2"> | |
| {/* Run Tests (Local Python Sandbox) */} | |
| <button | |
| onClick={onRunSandbox} | |
| disabled={sandboxRunning || !code.trim()} | |
| className="w-7 h-7 bg-emerald-600 hover:bg-emerald-500 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-white flex items-center justify-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed transition-all" | |
| title={sandboxRunning ? 'Running sandbox tests...' : 'Run tests in local sandbox'} | |
| aria-label="Run tests" | |
| > | |
| {sandboxRunning ? ( | |
| <RefreshCw className="w-3.5 h-3.5 animate-spin" /> | |
| ) : ( | |
| <Play className="w-3.5 h-3.5 fill-white text-white ml-0.5" /> | |
| )} | |
| </button> | |
| {/* Gemini AI Evaluation */} | |
| <button | |
| onClick={onAiEvaluation} | |
| disabled={aiLoading || !code.trim()} | |
| className="w-7 h-7 bg-purple-600 hover:bg-purple-500 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-white flex items-center justify-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed transition-all" | |
| title={aiLoading ? 'Evaluating code with Gemini...' : 'Gemini Eval (AI code review & complexity)'} | |
| aria-label="Gemini Eval" | |
| > | |
| {aiLoading ? ( | |
| <RefreshCw className="w-3.5 h-3.5 animate-spin" /> | |
| ) : ( | |
| <Sparkles className="w-3.5 h-3.5 text-amber-300" /> | |
| )} | |
| </button> | |
| </div> | |
| </div> | |
| <div className="p-4 sm:p-5 flex-1 flex flex-col space-y-4"> | |
| {/* Editor Shell - Pure Code Editor */} | |
| <div className="flex-1 flex flex-col min-h-[300px] sm:min-h-[360px] border-[3px] border-ink-black shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] bg-[#0c111d] overflow-hidden"> | |
| <div className="flex-1 overflow-hidden relative"> | |
| <CodeMirror | |
| value={code} | |
| onChange={onChangeCode} | |
| placeholder="def solve(nums): # Write your solution from memory here..." | |
| height="100%" | |
| theme="dark" | |
| extensions={codeStudioExtensions} | |
| basicSetup={{ | |
| autocompletion: isAutocompleteEnabled, | |
| lineNumbers: true, | |
| foldGutter: true, | |
| dropCursor: true, | |
| allowMultipleSelections: true, | |
| indentOnInput: true, | |
| bracketMatching: true, | |
| closeBrackets: true, | |
| rectangularSelection: true, | |
| crosshairCursor: true, | |
| highlightActiveLine: true, | |
| highlightSelectionMatches: true, | |
| closeBracketsKeymap: true, | |
| defaultKeymap: true, | |
| searchKeymap: true, | |
| historyKeymap: true, | |
| foldKeymap: true, | |
| completionKeymap: true, | |
| lintKeymap: true, | |
| }} | |
| className="w-full h-full text-xs font-code-mono" | |
| /> | |
| </div> | |
| </div> | |
| {/* Solution Saved Feedback Banner */} | |
| {savedRefSuccess && ( | |
| <div className="p-3 bg-[#f0fdf4] border-2 border-emerald-600 text-emerald-950 text-xs font-semibold flex items-center gap-2 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]"> | |
| <CheckCircle2 className="w-4 h-4 text-emerald-600 shrink-0" /> | |
| <span>Successfully saved studio code as your personal reference solution!</span> | |
| </div> | |
| )} | |
| {/* Solution Save Error Alert */} | |
| {saveRefError && ( | |
| <div className="p-3 bg-rose-50 border-2 border-rose-500 text-rose-800 text-xs font-semibold flex items-center gap-2 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]"> | |
| <AlertTriangle className="w-4 h-4 text-rose-600 shrink-0" /> | |
| <span>{saveRefError}</span> | |
| </div> | |
| )} | |
| {/* GitHub Commit Feedback Banner */} | |
| {githubPushedUrl && ( | |
| <div className="p-3 bg-[#f0fdf4] border-2 border-emerald-600 text-emerald-950 text-xs font-semibold flex items-center justify-between shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]"> | |
| <div className="flex items-center gap-2"> | |
| <CheckCircle2 className="w-4 h-4 text-emerald-600 shrink-0" /> | |
| <span>Successfully pushed solution to your GitHub repository!</span> | |
| </div> | |
| <a | |
| href={githubPushedUrl} | |
| target="_blank" | |
| rel="noopener noreferrer" | |
| className="text-[11px] font-bold text-blue-700 hover:text-blue-900 underline flex items-center gap-1" | |
| > | |
| <span>View on GitHub</span> | |
| <ExternalLink className="w-3 h-3" /> | |
| </a> | |
| </div> | |
| )} | |
| {/* GitHub Push Error Alert */} | |
| {githubPushError && ( | |
| <div className="p-3 bg-rose-50 border-2 border-rose-500 text-rose-800 text-xs font-semibold flex items-center gap-2 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]"> | |
| <AlertTriangle className="w-4 h-4 text-rose-600 shrink-0" /> | |
| <span>{githubPushError}</span> | |
| </div> | |
| )} | |
| {/* Sandbox Running Scanner */} | |
| {sandboxRunning && ( | |
| <div className="p-3 border-2 border-ink-black bg-emerald-50 shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] flex items-center gap-3 animate-pulse"> | |
| <RefreshCw className="w-5 h-5 text-emerald-600 animate-spin shrink-0" /> | |
| <div> | |
| <h4 className="font-arcade text-[9px] font-bold text-ink-black uppercase"> | |
| Running... | |
| </h4> | |
| <p className="font-sans text-[11px] text-trash-gray font-semibold mt-0.5"> | |
| Executing against test cases... | |
| </p> | |
| </div> | |
| </div> | |
| )} | |
| {/* Sandbox Error Alert */} | |
| {sandboxError && ( | |
| <div className="p-3 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-semibold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] flex items-center gap-2"> | |
| <AlertTriangle className="w-4 h-4 text-rose-600 shrink-0" /> | |
| <span>{sandboxError}</span> | |
| </div> | |
| )} | |
| {/* Sandbox Results Card */} | |
| {sandboxResults && ( | |
| <div | |
| className={`border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-3.5 ${sandboxResults.status === 'passed' ? 'bg-[#f0fdf4]' : 'bg-[#fff1f2]' | |
| }`} | |
| > | |
| {/* Result Status Header */} | |
| <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 pb-2.5 border-b-2 border-dashed border-ink-black"> | |
| <div className="flex items-center gap-2.5"> | |
| <div | |
| className={`w-8 h-8 border-2 border-ink-black flex items-center justify-center font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] ${sandboxResults.status === 'passed' ? 'bg-grass-green text-ink-black' : 'bg-rose-500 text-white' | |
| }`} | |
| > | |
| {sandboxResults.status === 'passed' ? ( | |
| <Check className="w-5 h-5 stroke-[3]" /> | |
| ) : ( | |
| <AlertTriangle className="w-4 h-4" /> | |
| )} | |
| </div> | |
| <div> | |
| <div className="font-arcade text-[10px] font-bold text-ink-black flex items-center gap-1.5 uppercase"> | |
| {sandboxResults.status === 'passed' ? ( | |
| <> | |
| <span>ALL TESTS PASSED</span> | |
| <CheckCircle2 className="w-3.5 h-3.5 text-emerald-600 inline" /> | |
| </> | |
| ) : ( | |
| <> | |
| <span>{sandboxResults.status === 'error' ? 'EXECUTION ERROR' : 'TESTS FAILED'}</span> | |
| <XCircle className="w-3.5 h-3.5 text-rose-600 inline" /> | |
| </> | |
| )} | |
| </div> | |
| <div className="font-sans text-[11px] text-slate-600 font-semibold"> | |
| {sandboxResults.passed_count ?? 0} of {sandboxResults.total_tests ?? 0} test cases passed ({(sandboxResults.duration_ms ?? 0).toFixed(1)}ms) | |
| </div> | |
| </div> | |
| </div> | |
| {/* Save Solution Button if passed */} | |
| {sandboxResults.status === 'passed' && ( | |
| <button | |
| onClick={onSaveReference} | |
| disabled={savingReference} | |
| className="px-3 py-1.5 bg-white hover:bg-emerald-100 border-2 border-ink-black text-ink-black font-arcade text-[8px] font-bold flex items-center gap-1.5 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0 disabled:opacity-50" | |
| > | |
| {savingReference ? ( | |
| <RefreshCw className="w-3 h-3 animate-spin" /> | |
| ) : savedRefSuccess ? ( | |
| <CheckCircle2 className="w-3.5 h-3.5 text-emerald-600" /> | |
| ) : ( | |
| <Save className="w-3.5 h-3.5 text-blue-600" /> | |
| )} | |
| <span>{savedRefSuccess ? 'SAVED TO DB!' : 'SAVE AS OFFICIAL SOLUTION'}</span> | |
| </button> | |
| )} | |
| </div> | |
| {saveRefError && ( | |
| <div className="p-2 border border-rose-500 bg-rose-100 text-rose-800 text-[11px] font-semibold"> | |
| {saveRefError} | |
| </div> | |
| )} | |
| {/* Test Case Breakdown */} | |
| {sandboxResults.results && sandboxResults.results.length > 0 && ( | |
| <div className="space-y-2"> | |
| <span className="font-arcade text-[8px] text-trash-gray uppercase font-bold block"> | |
| TEST CASE BREAKDOWN: | |
| </span> | |
| <div className="space-y-1.5 max-h-56 overflow-y-auto custom-scrollbar"> | |
| {sandboxResults.results.map((tc, idx) => ( | |
| <div | |
| key={idx} | |
| className={`p-2.5 border-2 border-ink-black text-xs font-mono shadow-[2px_2px_0px_0px_rgba(30,41,59,0.3)] ${tc.passed ? 'bg-white' : 'bg-rose-50' | |
| }`} | |
| > | |
| <div className="flex items-center justify-between font-arcade text-[8px] mb-1"> | |
| <span className="font-bold text-ink-black">CASE #{idx + 1}</span> | |
| <span className={tc.passed ? 'text-emerald-700 font-bold' : 'text-rose-700 font-bold'}> | |
| {tc.passed ? '✓ PASSED' : '✗ FAILED'} | |
| </span> | |
| </div> | |
| <div className="grid grid-cols-1 sm:grid-cols-3 gap-1.5 text-[10px]"> | |
| <div> | |
| <span className="text-slate-500 block">Input:</span> | |
| <span className="font-code-mono text-ink-black font-semibold break-all">{JSON.stringify(tc.input)}</span> | |
| </div> | |
| <div> | |
| <span className="text-slate-500 block">Expected:</span> | |
| <span className="font-code-mono text-emerald-700 font-semibold break-all">{JSON.stringify(tc.expected)}</span> | |
| </div> | |
| <div> | |
| <span className="text-slate-500 block">Output:</span> | |
| <span className={`font-code-mono font-semibold break-all ${tc.passed ? 'text-emerald-700' : 'text-rose-700'}`}> | |
| {tc.output !== undefined ? JSON.stringify(tc.output) : 'None'} | |
| </span> | |
| </div> | |
| </div> | |
| {tc.error && ( | |
| <div className="mt-1.5 p-1.5 bg-rose-100 text-rose-900 text-[10px] font-mono border border-rose-300 break-all"> | |
| {tc.error} | |
| </div> | |
| )} | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| )} | |
| {/* Error Trace if runtime error occurred */} | |
| {sandboxResults.error && ( | |
| <div className="p-3 bg-[#1E293B] text-rose-400 font-code-mono text-[11px] border-2 border-ink-black overflow-x-auto whitespace-pre-wrap select-text"> | |
| {sandboxResults.error} | |
| </div> | |
| )} | |
| {/* Smashed it shortcut hint if passed */} | |
| {sandboxResults.status === 'passed' && ( | |
| <div className="p-2 bg-emerald-100/70 border border-emerald-300 text-emerald-900 text-xs flex items-center justify-between"> | |
| <span className="font-sans font-medium"> | |
| ✨ All unit tests passed. Rate your recall below. | |
| </span> | |
| </div> | |
| )} | |
| </div> | |
| )} | |
| {/* AI Loading Scanner */} | |
| {aiLoading && ( | |
| <div className="p-4 border-2 border-ink-black bg-amber-50 shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] flex items-center gap-3 animate-pulse"> | |
| <RefreshCw className="w-6 h-6 text-purple-600 animate-spin shrink-0" /> | |
| <div> | |
| <h4 className="font-arcade text-[9px] font-bold text-ink-black uppercase"> | |
| ANALYZING... | |
| </h4> | |
| <p className="font-sans text-[11px] text-trash-gray font-semibold mt-0.5"> | |
| Checking edge cases, bounds, and Big-O efficiency against optimal constraints... | |
| </p> | |
| </div> | |
| </div> | |
| )} | |
| {/* AI Error Alert */} | |
| {aiError && ( | |
| <div className="p-3 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-semibold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]"> | |
| {aiError} | |
| </div> | |
| )} | |
| {/* AI Result Card */} | |
| {aiResult && ( | |
| <div className="border-[3px] border-ink-black bg-[#fefce8] p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-4"> | |
| {/* Verdict Banner */} | |
| <div className="flex items-center justify-between pb-3 border-b-2 border-dashed border-ink-black"> | |
| <div className="flex items-center gap-3"> | |
| <div | |
| className={`w-9 h-9 border-2 border-ink-black flex items-center justify-center font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] ${aiResult.is_correct | |
| ? 'bg-grass-green text-ink-black' | |
| : 'bg-rose-500 text-white' | |
| }`} | |
| > | |
| {aiResult.is_correct ? <Check className="w-5 h-5 stroke-[3]" /> : <Award className="w-5 h-5" />} | |
| </div> | |
| <div> | |
| <span className="font-arcade text-[10px] font-bold text-ink-black flex items-center gap-1.5"> | |
| {aiResult.is_correct ? ( | |
| <> | |
| STATUS: PASSED | |
| <CheckCircle2 className="w-3.5 h-3.5 text-emerald-600 inline" /> | |
| </> | |
| ) : ( | |
| <> | |
| STATUS: FAILED | |
| <XCircle className="w-3.5 h-3.5 text-rose-600 inline" /> | |
| </> | |
| )} | |
| </span> | |
| <span className="font-sans text-[11px] text-slate-600 font-semibold"> | |
| {aiResult.is_correct | |
| ? 'Algorithm matches expected logic and patterns.' | |
| : 'Bugs or edge-case failures detected.'} | |
| </span> | |
| </div> | |
| </div> | |
| <span | |
| className={`font-arcade text-[9px] px-2 py-1 border-2 border-ink-black uppercase font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] ${aiResult.is_correct | |
| ? 'bg-emerald-100 text-emerald-800' | |
| : 'bg-rose-100 text-rose-800' | |
| }`} | |
| > | |
| {aiResult.is_correct ? 'CORRECT' : 'INCORRECT'} | |
| </span> | |
| </div> | |
| {/* Complexity Comparison Grid */} | |
| <div className="grid grid-cols-2 gap-3"> | |
| <div className="p-2.5 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]"> | |
| <span className="font-arcade text-[8px] text-trash-gray block uppercase font-bold"> | |
| Time Complexity | |
| </span> | |
| <div className="flex items-baseline gap-2 mt-1"> | |
| <span className="font-code-mono text-xs font-bold text-ink-black"> | |
| {aiResult.detected_complexity?.time || 'N/A'} | |
| </span> | |
| <span className="text-[10px] font-sans text-slate-500 font-semibold"> | |
| (Target: {optimalTime || 'O(N)'}) | |
| </span> | |
| </div> | |
| </div> | |
| <div className="p-2.5 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]"> | |
| <span className="font-arcade text-[8px] text-trash-gray block uppercase font-bold"> | |
| Space Complexity | |
| </span> | |
| <div className="flex items-baseline gap-2 mt-1"> | |
| <span className="font-code-mono text-xs font-bold text-ink-black"> | |
| {aiResult.detected_complexity?.space || 'N/A'} | |
| </span> | |
| <span className="text-[10px] font-sans text-slate-500 font-semibold"> | |
| (Target: {optimalSpace || 'O(1)'}) | |
| </span> | |
| </div> | |
| </div> | |
| </div> | |
| {/* Bugs or Traps */} | |
| {aiResult.bugs && aiResult.bugs.length > 0 && ( | |
| <div className="p-3 bg-white border-2 border-ink-black space-y-1.5 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]"> | |
| <span className="font-arcade text-[8px] text-rose-600 uppercase font-bold block flex items-center gap-1"> | |
| <AlertTriangle className="w-3 h-3 text-rose-500" /> | |
| TRACES & EDGE CASE ISSUES: | |
| </span> | |
| <ul className="list-disc list-inside text-xs text-slate-800 space-y-1 font-semibold pl-1"> | |
| {aiResult.bugs.map((bug: string, idx: number) => ( | |
| <li key={idx} className="leading-relaxed select-text"> | |
| {bug} | |
| </li> | |
| ))} | |
| </ul> | |
| </div> | |
| )} | |
| {/* Refactoring Tip */} | |
| {aiResult.key_suggestion && ( | |
| <div className="p-3 bg-amber-50 border-2 border-ink-black space-y-1 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]"> | |
| <span className="font-arcade text-[8px] text-amber-700 uppercase font-bold block flex items-center gap-1"> | |
| <Sparkles className="w-3 h-3 text-amber-500" /> | |
| TIP: | |
| </span> | |
| <p className="text-xs text-slate-800 font-medium leading-relaxed m-0 select-text"> | |
| {aiResult.key_suggestion} | |
| </p> | |
| </div> | |
| )} | |
| {/* Recommendation Callout */} | |
| <div className="p-2.5 bg-white border-2 border-dashed border-ink-black flex items-center justify-between"> | |
| <span className="text-xs font-bold text-ink-black flex items-center gap-1.5"> | |
| <Info className="w-4 h-4 text-primary" /> | |
| Recommendation: | |
| </span> | |
| <span className="font-arcade text-[9px] font-bold text-purple-700"> | |
| {aiResult.is_correct | |
| ? 'Rate your recall below.' | |
| : 'Review issues and rate recall below.'} | |
| </span> | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| ); | |
| }; | |