feat(error): add button to reset app data

This commit is contained in:
Paul 2021-12-25 16:41:57 +00:00
parent 064f223c78
commit a23230850a

View file

@ -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>