mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-26 09:00:57 -05:00
feat(error): add button to reset app data
This commit is contained in:
parent
064f223c78
commit
a23230850a
1 changed files with 15 additions and 1 deletions
|
@ -1,8 +1,9 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import localforage from "localforage";
|
||||||
import * as stackTrace from "stacktrace-js";
|
import * as stackTrace from "stacktrace-js";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
|
|
||||||
import { useEffect, useErrorBoundary } from "preact/hooks";
|
import { useEffect, useErrorBoundary, useState } from "preact/hooks";
|
||||||
|
|
||||||
import { GIT_REVISION } from "../revision";
|
import { GIT_REVISION } from "../revision";
|
||||||
import { Children } from "../types/Preact";
|
import { Children } from "../types/Preact";
|
||||||
|
@ -42,6 +43,16 @@ export function reportError(error: Error, section: string) {
|
||||||
|
|
||||||
export default function ErrorBoundary({ children, section }: Props) {
|
export default function ErrorBoundary({ children, section }: Props) {
|
||||||
const [error, ignoreError] = useErrorBoundary();
|
const [error, ignoreError] = useErrorBoundary();
|
||||||
|
const [confirm, setConfirm] = useState(false);
|
||||||
|
|
||||||
|
async function reset() {
|
||||||
|
if (confirm) {
|
||||||
|
await localforage.clear();
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
setConfirm(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -58,6 +69,9 @@ export default function ErrorBoundary({ children, section }: Props) {
|
||||||
<button onClick={ignoreError}>
|
<button onClick={ignoreError}>
|
||||||
Ignore error and try to reload app
|
Ignore error and try to reload app
|
||||||
</button>
|
</button>
|
||||||
|
<button onClick={reset}>
|
||||||
|
{confirm ? "Are you sure?" : "Reset all app data"}
|
||||||
|
</button>
|
||||||
<button onClick={() => location.reload()}>
|
<button onClick={() => location.reload()}>
|
||||||
Refresh page
|
Refresh page
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in a new issue