Untitled conversation
- User
import React, { useState, useEffect, useRef } from 'react' interface Task { id: string name: string type: 'compute' | 'network' | 'memory' load: number priority: number active: boolean progress: number metrics: { cpu: number memory: number network: number disk: number } } interface SystemMetrics { totalCpu: number totalMemory: number totalNetwork: number totalDisk: number systemPressure: number } interface TilePosition { x: number y: number z: number } const MechanicalDesktop: React.FC = () => { const [tasks, setTasks] = useState<Task[]>([ { id: 'download', name: 'FILE.TRANSFER', type: 'network', load: 65, priority: 2, active: true, progress: 42, metrics: { cpu: 15, memory: 30, network: 85, disk: 60 } }, { id: 'editor', name: 'APP.COMPUTE', type: 'compute', load: 40, priority: 1, active: true, progress: 78, metrics: { cpu: 75, memory: 45, network: 10, disk: 20 } }, { id: 'sync', name: 'SYNC.DAEMON', type: 'memory', load: 20, priority: 3, active: false, progress: 100, metrics: { cpu: 25, memory: 60, network: 35, disk: 40 } } ]) const [systemMetrics, setSystemMetrics] = useState<SystemMetrics>({ totalCpu: 45, totalMemory: 52, totalNetwork: 38, totalDisk: 41, systemPressure: 0.45 }) const [tilePositions, setTilePositions] = useState<{ [key: string]: TilePosition }>({ download: { x: 1, y: 1, z: 2 }, editor: { x: 2, y: 1, z: 3 }, sync: { x: 3, y: 1, z: 1 }, cpu: { x: 1, y: 2, z: 1 }, memory: { x: 2, y: 2, z: 1 }, network: { x: 3, y: 2, z: 1 }, disk: { x: 4, y: 2, z: 1 }, power: { x: 1, y: 3, z: 1 }, thermal: { x: 2, y: 3, z: 1 }, process: { x: 3, y: 3, z: 1 }, kernel: { x: 4, y: 3, z: 1 } }) const [draggedTile, setDraggedTile] = useState<string | null>(null) const [pulsePhase, setPulsePhase] = useState(0) const [breathPhase, setBreathPhase] = useState(0) const animationFrame = useRef<number>() // Simulation engine useEffect(() => { const interval = setInterval(() => { setTasks(prevTasks => prevTasks.map(task => { if (!task.active) return task const loadDelta = (Math.random() - 0.5) * 10 const newLoad = Math.max(0, Math.min(100, task.load + loadDelta)) const progressDelta = task.type === 'network' ? 0.8 : 0.3 const newProgress = task.progress >= 100 ? 0 : task.progress + progressDelta return { ...task, load: newLoad, progress: newProgress, metrics: { cpu: Math.max(0, Math.min(100, task.metrics.cpu + (Math.random() - 0.5) * 5)), memory: Math.max(0, Math.min(100, task.metrics.memory + (Math.random() - 0.5) * 3)), network: Math.max(0, Math.min(100, task.metrics.network + (Math.random() - 0.5) * 8)), disk: Math.max(0, Math.min(100, task.metrics.disk + (Math.random() - 0.5) * 4)) } } })) setSystemMetrics(prev => ({ totalCpu: Math.max(0, Math.min(100, prev.totalCpu + (Math.random() - 0.5) * 5)), totalMemory: Math.max(0, Math.min(100, prev.totalMemory + (Math.random() - 0.5) * 3)), totalNetwork: Math.max(0, Math.min(100, prev.totalNetwork + (Math.random() - 0.5) * 7)), totalDisk: Math.max(0, Math.min(100, prev.totalDisk + (Math.random() - 0.5) * 4)), systemPressure: Math.max(0, Math.min(1, prev.systemPressure + (Math.random() - 0.5) * 0.1)) })) }, 100) return () => clearInterval(interval) }, []) // Animation loop for breathing and pulsing useEffect(() => { const animate = () => { setPulsePhase(prev => (prev + 0.1) % (Math.PI * 2)) setBreathPhase(prev => { const speed = 0.02 const next = prev + speed return next % (Math.PI * 2) }) animationFrame.current = requestAnimationFrame(animate) } animate() return () => { if (animationFrame.current) cancelAnimationFrame(animationFrame.current) } }, []) const handleTaskToggle = (taskId: string) => { setTasks(prev => prev.map(task => task.id === taskId ? { ...task, active: !task.active } : task )) } const handleLoadChange = (taskId: string, newLoad: number) => { setTasks(prev => prev.map(task => task.id === taskId ? { ...task, load: newLoad } : task )) } const handlePriorityChange = (taskId: string, newPriority: number) => { setTasks(prev => prev.map(task => task.id === taskId ? { ...task, priority: newPriority } : task )) } const handleTileDrag = (tileId: string) => { setDraggedTile(tileId) setTilePositions(prev => ({ ...prev, [tileId]: { ...prev[tileId], z: 4 } })) } const handleTileDrop = () => { setDraggedTile(null) } const getTaskColor = (type: 'compute' | 'network' | 'memory') => { switch(type) { case 'compute': return 'cyan' case 'network': return 'blue' case 'memory': return 'violet' default: return 'gray' } } const getPulseIntensity = (load: number, active: boolean) => { if (!active) return 0.1 const base = 0.3 const variable = (Math.sin(pulsePhase * (1 + load / 25)) + 1) / 2 return base + variable * (load / 100) * 0.7 } const getBreathScale = () => { const inhale = Math.pow(Math.sin(breathPhase), 2) const exhale = Math.pow(Math.cos(breathPhase), 4) return 1 + (inhale * 0.03) - (exhale * 0.02) } return ( <div className="relative w-full h-screen bg-gray-900 overflow-hidden"> {/* Background grid pattern */} <div className="absolute inset-0 opacity-20"> <div className="absolute inset-0" style={{ backgroundImage: `linear-gradient(to right, #1f2937 1px, transparent 1px),\n linear-gradient(to bottom, #1f2937 1px, transparent 1px)`, backgroundSize: '40px 40px' }} /> </div> {/* Data flow conduits */} <svg className="absolute inset-0 pointer-events-none" style={{ zIndex: 5 }}> {tasks.map((task) => { const pos = tilePositions[task.id] const intensity = task.active ? task.load / 100 : 0 return ( <g key={task.id}> <line x1={pos.x * 200} y1={pos.y * 200} x2={window.innerWidth / 2} y2={window.innerHeight / 2} stroke={getTaskColor(task.type)} strokeWidth={2 + intensity * 2} strokeOpacity={0.3 + intensity * 0.4} strokeDasharray={task.active ? "5,5" : "2,8"} className="transition-all duration-300" > {task.active && ( <animate attributeName="stroke-dashoffset" values="0;10" dur={`${2 - intensity}s`} repeatCount="indefinite" /> )} </line> </g> ) })} </svg> {/* Main grid container */} <div className="relative p-8 h-full"> <div className="grid grid-cols-5 grid-rows-4 gap-4 h-full"> {/* Task Tiles */} {tasks.map((task) => { const pos = tilePositions[task.id] const color = getTaskColor(task.type) const pulseIntensity = getPulseIntensity(task.load, task.active) const breathScale = getBreathScale() return ( <div key={task.id} className="relative col-span-2 row-span-2 cursor-move transition-all duration-300" style={{ gridColumn: `${pos.x} / span 2`, gridRow: `${pos.y} / span 2`, zIndex: pos.z * 10, transform: `scale(${task.active ? breathScale : 1}) translateZ(${pos.z * 10}px)`, opacity: task.active ? 0.9 + pulseIntensity * 0.1 : 0.6 }} onMouseDown={() => handleTileDrag(task.id)} onMouseUp={handleTileDrop} > <div className={`relative h-full rounded-lg border-2 p-4 backdrop-blur-md transition-all duration-300`} style={{ backgroundColor: `rgba(0, 0, 0, ${task.active ? 0.7 : 0.9})`, borderColor: color, borderWidth: task.active ? '2px' : '1px', boxShadow: task.active ? `0 0 ${20 + task.load / 5}px ${color}88, inset 0 0 ${10 + task.load / 10}px ${color}44` : 'none' }} > {/* Title bar */} <div className="flex justify-between items-center mb-3"> <h3 className={`text-sm font-mono font-bold tracking-wider ${ color === 'cyan' ? 'text-cyan-400' : color === 'blue' ? 'text-blue-400' : color === 'violet' ? 'text-violet-400' : 'text-gray-400' }`}> {task.name} </h3> <div className="flex items-center gap-2"> <span className={`text-xs font-mono ${ task.active ? 'text-green-400' : 'text-red-500' }`}> {task.active ? 'ACTIVE' : 'IDLE'} </span> <button onClick={() => handleTaskToggle(task.id)} className={`w-12 h-6 rounded-full transition-all duration-300 relative ${ task.active ? 'bg-green-900' : 'bg-gray-800' }`} > <div className={`absolute top-1 w-4 h-4 rounded-full transition-all duration-300 ${ task.active ? 'left-7 bg-green-400 shadow-lg shadow-green-400/50' : 'left-1 bg-gray-600' }`} /> </button> </div> </div> {/* Progress bar */} <div className="mb-3"> <div className="flex justify-between text-xs font-mono text-gray-500 mb-1"> <span>PROGRESS</span> <span>{Math.round(task.progress)}%</span> </div> <div className="h-2 bg-gray-800 rounded-full overflow-hidden"> <div className="h-full transition-all duration-500" style={{ width: `${task.progress}%`, backgroundColor: color, boxShadow: task.active ? `0 0 10px ${color}` : 'none' }} /> </div> </div> {/* Load control */} <div className="mb-3"> <div className="flex justify-between text-xs font-mono text-gray-500 mb-1"> <span>LOAD</span> <span>{Math.round(task.load)}%</span> </div> <input type="range" min="0" max="100" value={task.load} onChange={(e) => handleLoadChange(task.id, parseInt(e.target.value))} className="w-full h-8 appearance-none bg-gray-800 rounded-lg cursor-pointer" style={{ background: `linear-gradient(to right, ${color} 0%, ${color} ${task.load}%, #1f2937 ${task.load}%, #1f2937 100%)` }} /> </div> {/* Priority control */} <div className="mb-3"> <div className="flex justify-between text-xs font-mono text-gray-500 mb-1"> <span>PRIORITY</span> <span>P{task.priority}</span> </div> <div className="flex gap-1"> {[1, 2, 3].map(p => ( <button key={p} onClick={() => handlePriorityChange(task.id, p)} className={`flex-1 h-6 rounded transition-all duration-300 font-mono text-xs ${ task.priority === p ? `bg-${color}-900 text-${color}-400 border border-${color}-400` : 'bg-gray-800 text-gray-600 border border-gray-700' }`} style={{ boxShadow: task.priority === p ? `0 0 5px ${color}66` : 'none' }} > P{p} </button> ))} </div> </div> {/* Mini metrics */} <div className="grid grid-cols-2 gap-2"> {Object.entries(task.metrics).map(([key, value]) => ( <div key={key} className="bg-gray-800 rounded p-2"> <div className="text-xs font-mono text-gray-500 mb-1"> {key.toUpperCase()} </div> <div className="h-1 bg-gray-900 rounded-full overflow-hidden"> <div className="h-full transition-all duration-300" style={{ width: `${value}%`, backgroundColor: key === 'cpu' ? 'cyan' : key === 'memory' ? 'violet' : key === 'network' ? 'blue' : 'green', opacity: task.active ? 0.8 : 0.3 }} /> </div> </div> ))} </div> </div> </div> ) })} {/* System Metrics Tiles */} <div className="col-start-1 col-span-1 row-start-3" style={{ zIndex: 20 }}> <div className="h-full bg-gray-900 bg-opacity-80 border border-gray-700 rounded-lg p-3"> <h4 className="text-xs font-mono text-cyan-400 mb-2">CPU.CORE</h4> <div className="relative h-20"> <div className="absolute bottom-0 w-full flex items-end justify-between gap-1"> {[...Array(8)].map((_, i) => ( <div key={i} className="flex-1 bg-cyan-600 rounded-t transition-all duration-300" style={{ height: `${20 + Math.random() * 60}%`, opacity: 0.3 + (systemMetrics.totalCpu / 100) * 0.7 }} /> ))} </div> </div> <div className="text-xs font-mono text-gray-500 mt-2"> {Math.round(systemMetrics.totalCpu)}% </div> </div> </div> <div className="col-start-2 col-span-1 row-start-3" style={{ zIndex: 20 }}> <div className="h-full bg-gray-900 bg-opacity-80 border border-gray-700 rounded-lg p-3"> <h4 className="text-xs font-mono text-violet-400 mb-2">MEM.USAGE</h4> <div className="relative h-20"> <div className="absolute inset-0 flex items-center justify-center"> <div className="w-16 h-16 rounded-full border-4 border-violet-600" style={{ background: `conic-gradient(violet ${systemMetrics.totalMemory * 3.6}deg, transparent 0)`, opacity: 0.3 + (systemMetrics.totalMemory / 100) * 0.7 }} /> </div> </div> <div className="text-xs font-mono text-gray-500 mt-2 text-center"> {Math.round(systemMetrics.totalMemory)}% </div> </div> </div> <div className="col-start-3 col-span-1 row-start-3" style={{ zIndex: 20 }}> <div className="h-full bg-gray-900 bg-opacity-80 border border-gray-700 rounded-lg p-3"> <h4 className="text-xs font-mono text-blue-400 mb-2">NET.FLOW</h4> <div className="relative h-20 overflow-hidden"> <div className="absolute inset-0 flex items-end"> {[...Array(16)].map((_, i) => ( <div key={i} className="flex-1 mx-px" > <div className="w-full bg-blue-600 rounded-t" style={{ height: `${Math.sin((pulsePhase + i * 0.5) * 2) * 30 + 40}%`, opacity: 0.3 + (systemMetrics.totalNetwork / 100) * 0.7 }} /> </div> ))} </div> </div> <div className="text-xs font-mono text-gray-500 mt-2"> {Math.round(systemMetrics.totalNetwork)} Mb/s </div> </div> </div> <div className="col-start-4 col-span-1 row-start-3" style={{ zIndex: 20 }}> <div className="h-full bg-gray-900 bg-opacity-80 border border-gray-700 rounded-lg p-3"> <h4 className="text-xs font-mono text-green-400 mb-2">DISK.IO</h4> <div className="grid grid-cols-4 gap-1 h-20"> {[...Array(16)].map((_, i) => ( <div key={i} className="bg-green-600 rounded" style={{ opacity: Math.random() > 0.5 ? 0.3 + (systemMetrics.totalDisk / 100) * 0.7 : 0.1 }} /> ))} </div> <div className="text-xs font-mono text-gray-500 mt-2"> {Math.round(systemMetrics.totalDisk)} MB/s </div> </div> </div> {/* System pressure indicator */} <div className="col-start-5 col-span-1 row-start-1 row-span-2" style={{ zIndex: 25 }}> <div className="h-full bg-gray-900 bg-opacity-90 border border-gray-700 rounded-lg p-4 flex flex-col"> <h4 className="text-xs font-mono text-orange-400 mb-4">SYS.PRESSURE</h4> <div className="flex-1 relative"> <div className="absolute inset-0 bg-gray-800 rounded-lg overflow-hidden"> <div className="absolute bottom-0 w-full transition-all duration-500" style={{ height: `${systemMetrics.systemPressure * 100}%`, background: `linear-gradient(to top, ${systemMetrics.systemPressure > 0.7 ? '#ef4444' : systemMetrics.systemPressure > 0.4 ? '#f59e0b' : '#10b981'} 0%, transparent 100%)`, boxShadow: systemMetrics.systemPressure > 0.7 ? '0 0 20px #ef444488' : 'none' }} /> {[...Array(10)].map((_, i) => ( <div key={i} className="absolute w-full border-t border-gray-700" style={{ bottom: `${i * 10}%` }} /> ))} </div> </div> <div className="text-xs font-mono text-gray-500 mt-2 text-center"> {Math.round(systemMetrics.systemPressure * 100)}% </div> </div> </div> {/* Terminal/Log window */} <div className="col-start-5 col-span-1 row-start-3 row-span-2" style={{ zIndex: 25 }}> <div className="h-full bg-black bg-opacity-90 border border-gray-700 rounded-lg p-3 font-mono text-xs overflow-hidden"> <div className="text-green-400 mb-2">KERNEL.LOG</div> <div className="space-y-1 text-gray-500"> {tasks.map(task => ( <div key={task.id} className="truncate"> <span className="text-gray-600">[{new Date().toISOString().substr(11, 8)}]</span> <span className={task.active ? 'text-green-500' : 'text-gray-600'}> {' '}{task.name}: {task.active ? 'RUNNING' : 'SUSPENDED'} </span> </div> ))} <div className="text-cyan-500">└─ CPU: {Math.round(systemMetrics.totalCpu)}%</div> <div className="text-violet-500">└─ MEM: {Math.round(systemMetrics.totalMemory)}%</div> <div className="text-blue-500">└─ NET: {Math.round(systemMetrics.totalNetwork)}Mb</div> </div> </div> </div> {/* Additional ambient tiles */} <div className="col-start-1 col-span-2 row-start-4" style={{ zIndex: 15 }}> <div className="h-full bg-gray-900 bg-opacity-70 border border-gray-700 rounded-lg p-3"> <h4 className="text-xs font-mono text-amber-400 mb-2">THERMAL.SENSORS</h4> <div className="flex gap-2"> {['CPU', 'GPU', 'SSD', 'FAN'].map(sensor => ( <div key={sensor} className="flex-1 text-center"> <div className="text-xs text-gray-500 mb-1">{sensor}</div> <div className={`text-sm font-mono ${ Math.random() > 0.7 ? 'text-orange-400' : 'text-green-400' }`}> {45 + Math.round(Math.random() * 30)}°C </div> </div> ))} </div> </div> </div> <div className="col-start-3 col-span-2 row-start-4" style={{ zIndex: 15 }}> <div className="h-full bg-gray-900 bg-opacity-70 border border-gray-700 rounded-lg p-3"> <h4 className="text-xs font-mono text-indigo-400 mb-2">PROCESS.TREE</h4> <div className="text-xs font-mono space-y-1"> <div className="text-gray-400">├─ systemd [PID 1]</div> <div className="text-gray-500">│ ├─ kernel.task [142]</div> <div className="text-gray-500">│ └─ user.session [256]</div> <div className="text-gray-600">└─ idle.workers [32]</div> </div> </div> </div> </div> </div> {/* Overlay effects */} <div className="absolute inset-0 pointer-events-none" style={{ background: `radial-gradient(circle at 50% 50%, transparent 0%, rgba(0,0,0,0.4) 100%)`, mixBlendMode: 'multiply' }} /> </div> ) } export default MechanicalDesktop Assistant
- User
ReferenceError: window is not defined at (pages/xx.tsx:221:21) at Array.map () at MechanicalDesktop (pages/xx.tsx:213:16) 219 | x1={pos.x * 200} 220 | y1={pos.y * 200}
221 | x2={window.innerWidth / 2} | ^ 222 | y2={window.innerHeight / 2} 223 | stroke={getTaskColor(task.type)} 224 | strokeWidth={2 + intensity * 2}
Assistant
- User
Post the full solution with your fix
Assistant
- User
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.