import React from "react"; import { IconButton } from "@/app/components/button"; import GithubIcon from "@/app/icons/github.svg"; import ResetIcon from "@/app/icons/reload.svg"; import { ISSUE_URL } from "@/app/constant"; import Locale from "@/app/locales"; import { showConfirm } from "@/app/components/ui-lib"; import { useSyncStore } from "@/app/store/sync"; interface IErrorBoundaryState { hasError: boolean; error: Error | null; info: React.ErrorInfo | null; } export class ErrorBoundary extends React.Component { constructor(props: any) { super(props); this.state = { hasError: false, error: null, info: null }; } componentDidCatch(error: Error, info: React.ErrorInfo) { // Update state with error details this.setState({ hasError: true, error, info }); } clearAndSaveData() { try { useSyncStore.getState().export(); } finally { localStorage.clear(); location.reload(); } } render() { if (this.state.hasError) { // Render error message return (

Oops, something went wrong!

            {this.state.error?.toString()}
            {this.state.info?.componentStack}
          
} bordered /> } text="Clear All Data" onClick={async () => { if (await showConfirm(Locale.Settings.Danger.Reset.Confirm)) { this.clearAndSaveData(); } }} bordered />
); } // if no error occurred, render children return this.props.children; } }