- Complete rewrite of frontend using React 18 + TypeScript in strict mode - Implement TanStack Router for file-based routing matching URL structure - Use TanStack Query for server state management with smart caching - Replace Pinia stores with React Context API for auth and UI state - Adopt Tailwind CSS + shadcn/ui components for consistent styling - Switch from pnpm to Bun for faster package management and builds - Configure Vite to support React, TypeScript, and modern tooling - Create frontend.go with Go embed package for embedding dist/ in binary - Implement comprehensive TypeScript interfaces (strict mode, no 'any' types) - Add dark mode support throughout with Tailwind CSS dark: classes - Set up i18n infrastructure (English translations included) - Remove all Vue 3 code, components, stores, CSS, and assets - Includes 18 new files with ~2000 lines of production-ready code
80 lines
2.7 KiB
TypeScript
80 lines
2.7 KiB
TypeScript
import React, { Component, ErrorInfo, ReactNode } from "react";
|
|
|
|
interface Props {
|
|
children: ReactNode;
|
|
fallback?: (error: Error, retry: () => void) => ReactNode;
|
|
}
|
|
|
|
interface State {
|
|
hasError: boolean;
|
|
error: Error | null;
|
|
}
|
|
|
|
/**
|
|
* Error Boundary component to catch React errors
|
|
* Displays a user-friendly error message instead of crashing
|
|
*/
|
|
export class ErrorBoundary extends Component<Props, State> {
|
|
public constructor(props: Props) {
|
|
super(props);
|
|
this.state = { hasError: false, error: null };
|
|
}
|
|
|
|
public static getDerivedStateFromError(error: Error): State {
|
|
return { hasError: true, error };
|
|
}
|
|
|
|
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
console.error("ErrorBoundary caught an error:", error, errorInfo);
|
|
}
|
|
|
|
private handleRetry = () => {
|
|
this.setState({ hasError: false, error: null });
|
|
};
|
|
|
|
public render() {
|
|
if (this.state.hasError) {
|
|
if (this.props.fallback && this.state.error) {
|
|
return this.props.fallback(this.state.error, this.handleRetry);
|
|
}
|
|
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center bg-gray-50 dark:bg-slate-950">
|
|
<div className="w-full max-w-md rounded-lg border border-red-200 bg-white p-6 shadow-lg dark:border-red-900 dark:bg-slate-800">
|
|
<h2 className="mb-4 text-lg font-semibold text-red-900 dark:text-red-200">
|
|
Oops! Something went wrong
|
|
</h2>
|
|
<p className="mb-4 text-sm text-red-800 dark:text-red-300">
|
|
{this.state.error?.message || "An unexpected error occurred"}
|
|
</p>
|
|
<details className="mb-4">
|
|
<summary className="cursor-pointer text-xs font-medium text-red-700 dark:text-red-400">
|
|
Error details
|
|
</summary>
|
|
<pre className="mt-2 overflow-auto rounded bg-red-50 p-2 text-xs dark:bg-red-950">
|
|
{this.state.error?.stack}
|
|
</pre>
|
|
</details>
|
|
<div className="flex gap-2">
|
|
<button
|
|
onClick={this.handleRetry}
|
|
className="flex-1 rounded-md bg-red-600 px-4 py-2 text-sm font-medium text-white hover:bg-red-700 dark:hover:bg-red-800"
|
|
>
|
|
Try Again
|
|
</button>
|
|
<button
|
|
onClick={() => window.location.href = "/"}
|
|
className="flex-1 rounded-md border border-red-200 px-4 py-2 text-sm font-medium text-red-600 hover:bg-red-50 dark:border-red-800 dark:text-red-400 dark:hover:bg-red-950"
|
|
>
|
|
Go Home
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return this.props.children;
|
|
}
|
|
}
|