mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-08 18:57:07 +08:00
feat: migrate state from v1 to v2
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import React from "react";
|
||||
import { IconButton } from "./button";
|
||||
import GithubIcon from "../icons/github.svg";
|
||||
import { ISSUE_URL } from "../constant";
|
||||
import ResetIcon from "../icons/reload.svg";
|
||||
import { ISSUE_URL, StoreKey } from "../constant";
|
||||
import Locale from "../locales";
|
||||
import { downloadAs } from "../utils";
|
||||
|
||||
interface IErrorBoundaryState {
|
||||
hasError: boolean;
|
||||
@@ -20,6 +23,25 @@ export class ErrorBoundary extends React.Component<any, IErrorBoundaryState> {
|
||||
this.setState({ hasError: true, error, info });
|
||||
}
|
||||
|
||||
clearAndSaveData() {
|
||||
const snapshot: Record<string, any> = {};
|
||||
Object.values(StoreKey).forEach((key) => {
|
||||
snapshot[key] = localStorage.getItem(key);
|
||||
|
||||
if (snapshot[key]) {
|
||||
try {
|
||||
snapshot[key] = JSON.parse(snapshot[key]);
|
||||
} catch {}
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
downloadAs(JSON.stringify(snapshot), "chatgpt-next-web-snapshot.json");
|
||||
} catch {}
|
||||
|
||||
localStorage.clear();
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.hasError) {
|
||||
// Render error message
|
||||
@@ -31,13 +53,23 @@ export class ErrorBoundary extends React.Component<any, IErrorBoundaryState> {
|
||||
<code>{this.state.info?.componentStack}</code>
|
||||
</pre>
|
||||
|
||||
<a href={ISSUE_URL} className="report">
|
||||
<div style={{ display: "flex", justifyContent: "space-between" }}>
|
||||
<a href={ISSUE_URL} className="report">
|
||||
<IconButton
|
||||
text="Report This Error"
|
||||
icon={<GithubIcon />}
|
||||
bordered
|
||||
/>
|
||||
</a>
|
||||
<IconButton
|
||||
text="Report This Error"
|
||||
icon={<GithubIcon />}
|
||||
icon={<ResetIcon />}
|
||||
text="Clear All Data"
|
||||
onClick={() =>
|
||||
confirm(Locale.Store.ConfirmClearAll) && this.clearAndSaveData()
|
||||
}
|
||||
bordered
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user