Spaces:
Running
Running
Download algospaced-ui/src/components/WindowErrorBoundary.tsx from iamfebin/algospaced-dsa: direct link, hf CLI and curl.
- Browser
- Download file 3.39 kB
-
https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/WindowErrorBoundary.tsx
- Command line
-
hf download hf://spaces/iamfebin/algospaced-dsa/algospaced-ui/src/components/WindowErrorBoundary.tsx
-
curl -L -o WindowErrorBoundary.tsx https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/WindowErrorBoundary.tsx
3.39 kB
| import React, { Component, type ReactNode } from 'react'; | |
| import { RotateCcw, X, AlertTriangle } from 'lucide-react'; | |
| interface WindowErrorBoundaryProps { | |
| windowId: string; | |
| windowTitle?: string; | |
| onClose?: () => void; | |
| children: ReactNode; | |
| } | |
| interface WindowErrorBoundaryState { | |
| hasError: boolean; | |
| error: Error | null; | |
| } | |
| export default class WindowErrorBoundary extends Component< | |
| WindowErrorBoundaryProps, | |
| WindowErrorBoundaryState | |
| > { | |
| constructor(props: WindowErrorBoundaryProps) { | |
| super(props); | |
| this.state = { hasError: false, error: null }; | |
| } | |
| static getDerivedStateFromError(error: Error): WindowErrorBoundaryState { | |
| return { hasError: true, error }; | |
| } | |
| componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { | |
| console.error( | |
| `[WindowErrorBoundary] Error caught in window "${this.props.windowId}":`, | |
| error, | |
| errorInfo | |
| ); | |
| } | |
| handleReset = () => { | |
| this.setState({ hasError: false, error: null }); | |
| }; | |
| render() { | |
| if (this.state.hasError) { | |
| return ( | |
| <div className="w-full h-full p-6 bg-[#0f172a] text-white flex flex-col items-center justify-center font-sans select-none overflow-auto"> | |
| <div className="max-w-md w-full bg-[#1e293b] border-[3px] border-rose-500 rounded-lg p-5 shadow-[6px_6px_0px_0px_rgba(0,0,0,0.5)] flex flex-col gap-4"> | |
| {/* Header */} | |
| <div className="flex items-center gap-2 text-rose-400 font-headline-md font-bold text-sm border-b border-slate-700 pb-2.5"> | |
| <AlertTriangle className="w-5 h-5 shrink-0" /> | |
| <span>SYSTEM INTERRUPT: {this.props.windowTitle || this.props.windowId}</span> | |
| </div> | |
| {/* Error Message */} | |
| <div className="bg-[#0b0f19] border border-slate-800 rounded p-3 font-mono text-[11px] text-rose-300 leading-relaxed max-h-32 overflow-y-auto custom-scrollbar"> | |
| {this.state.error?.message || 'An unexpected runtime error occurred.'} | |
| </div> | |
| <p className="text-[11px] text-slate-400 leading-relaxed"> | |
| The window process encountered a recoverable fault. You can restart this window module without losing your desktop session. | |
| </p> | |
| {/* Action Buttons */} | |
| <div className="flex items-center justify-end gap-2 pt-2 border-t border-slate-700"> | |
| {this.props.onClose && ( | |
| <button | |
| type="button" | |
| onClick={this.props.onClose} | |
| className="px-3 py-1.5 bg-slate-700 hover:bg-slate-600 text-white rounded text-xs font-bold transition-all flex items-center gap-1.5 cursor-pointer" | |
| > | |
| <X className="w-3.5 h-3.5" /> | |
| <span>Close Window</span> | |
| </button> | |
| )} | |
| <button | |
| type="button" | |
| onClick={this.handleReset} | |
| className="px-3 py-1.5 bg-rose-600 hover:bg-rose-500 text-white rounded text-xs font-bold transition-all shadow-[2px_2px_0px_0px_#000] active:translate-y-0.5 active:shadow-none flex items-center gap-1.5 cursor-pointer" | |
| > | |
| <RotateCcw className="w-3.5 h-3.5" /> | |
| <span>Restart Module</span> | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| return this.props.children; | |
| } | |
| } | |