Spaces:
Running
Running
Download algospaced-ui/src/components/RootErrorBoundary.tsx from iamfebin/algospaced-dsa: direct link, hf CLI and curl.
- Browser
- Download file 4.36 kB
-
https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/RootErrorBoundary.tsx
- Command line
-
hf download hf://spaces/iamfebin/algospaced-dsa/algospaced-ui/src/components/RootErrorBoundary.tsx
-
curl -L -o RootErrorBoundary.tsx https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/RootErrorBoundary.tsx
4.36 kB
| import { Component, type ReactNode, type ErrorInfo } from 'react'; | |
| import { RotateCcw, AlertOctagon, Trash2 } from 'lucide-react'; | |
| interface RootErrorBoundaryProps { | |
| children: ReactNode; | |
| } | |
| interface RootErrorBoundaryState { | |
| hasError: boolean; | |
| error: Error | null; | |
| } | |
| export default class RootErrorBoundary extends Component< | |
| RootErrorBoundaryProps, | |
| RootErrorBoundaryState | |
| > { | |
| constructor(props: RootErrorBoundaryProps) { | |
| super(props); | |
| this.state = { hasError: false, error: null }; | |
| } | |
| static getDerivedStateFromError(error: Error): RootErrorBoundaryState { | |
| return { hasError: true, error }; | |
| } | |
| componentDidCatch(error: Error, errorInfo: ErrorInfo) { | |
| console.error('[RootErrorBoundary] Fatal system error caught at OS root:', error, errorInfo); | |
| } | |
| handleReboot = () => { | |
| window.location.reload(); | |
| }; | |
| handleHardReset = () => { | |
| try { | |
| localStorage.clear(); | |
| sessionStorage.clear(); | |
| } catch (_) {} | |
| window.location.reload(); | |
| }; | |
| render() { | |
| if (this.state.hasError) { | |
| return ( | |
| <div className="fixed inset-0 z-[99999] bg-[#030712] text-white flex flex-col items-center justify-center p-6 font-mono select-none overflow-auto"> | |
| {/* CRT scanline simulation */} | |
| <div className="absolute inset-0 pointer-events-none bg-[radial-gradient(ellipse_at_center,transparent_0%,rgba(0,0,0,0.4)_100%)]" /> | |
| <div className="relative max-w-xl w-full bg-[#0b0f19] border-[3px] border-rose-500 rounded-lg p-6 shadow-[8px_8px_0px_0px_rgba(244,63,94,0.3)] flex flex-col gap-5"> | |
| {/* Header */} | |
| <div className="flex items-center gap-3 text-rose-400 border-b border-rose-950 pb-3"> | |
| <div className="p-2 bg-rose-500/10 rounded border border-rose-500/30"> | |
| <AlertOctagon className="w-6 h-6 text-rose-500 animate-pulse" /> | |
| </div> | |
| <div> | |
| <h1 className="text-sm font-bold tracking-wider uppercase text-rose-300 font-arcade"> | |
| ALGOSPACED_RECOVERY_CONSOLE | |
| </h1> | |
| <p className="text-[10px] text-rose-400/75 mt-0.5"> | |
| STOP: 0x000000D1 • DESKTOP_THREAD_EXCEPTION | |
| </p> | |
| </div> | |
| </div> | |
| {/* Error Details */} | |
| <div className="space-y-2"> | |
| <span className="text-[11px] text-slate-400 uppercase font-semibold tracking-wider block"> | |
| Fault Trace: | |
| </span> | |
| <div className="bg-[#020617] border border-slate-800 rounded p-3 text-[11px] text-rose-300 font-mono leading-relaxed max-h-36 overflow-y-auto custom-scrollbar break-all"> | |
| {this.state.error?.message || 'A fatal system exception was trapped by the OS kernel.'} | |
| </div> | |
| </div> | |
| <p className="text-xs text-slate-300 leading-relaxed"> | |
| A recoverable exception occurred in the primary desktop shell. Your local data and progress records are safely preserved in storage. | |
| </p> | |
| {/* Action Bar */} | |
| <div className="flex flex-col sm:flex-row items-stretch sm:items-center justify-end gap-3 pt-3 border-t border-slate-800"> | |
| <button | |
| type="button" | |
| onClick={this.handleHardReset} | |
| className="px-4 py-2 bg-slate-800 hover:bg-slate-700 text-slate-300 rounded text-xs font-bold transition-all border border-slate-700 flex items-center justify-center gap-2 cursor-pointer" | |
| title="Clears cached session data and resets workspace state" | |
| > | |
| <Trash2 className="w-3.5 h-3.5 text-slate-400" /> | |
| <span>Reset Cache & Reboot</span> | |
| </button> | |
| <button | |
| type="button" | |
| onClick={this.handleReboot} | |
| className="px-4 py-2 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 justify-center gap-2 cursor-pointer" | |
| > | |
| <RotateCcw className="w-3.5 h-3.5" /> | |
| <span>Reboot AlgoSpaced OS</span> | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| return this.props.children; | |
| } | |
| } | |