mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-25 23:22:06 -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 localforage from "localforage";
|
||||
import * as stackTrace from "stacktrace-js";
|
||||
import styled from "styled-components";
|
||||
|
||||
import { useEffect, useErrorBoundary } from "preact/hooks";
|
||||
import { useEffect, useErrorBoundary, useState } from "preact/hooks";
|
||||
|
||||
import { GIT_REVISION } from "../revision";
|
||||
import { Children } from "../types/Preact";
|
||||
|
@ -42,6 +43,16 @@ export function reportError(error: Error, section: string) {
|
|||
|
||||
export default function ErrorBoundary({ children, section }: Props) {
|
||||
const [error, ignoreError] = useErrorBoundary();
|
||||
const [confirm, setConfirm] = useState(false);
|
||||
|
||||
async function reset() {
|
||||
if (confirm) {
|
||||
await localforage.clear();
|
||||
location.reload();
|
||||
} else {
|
||||
setConfirm(true);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (error) {
|
||||
|
@ -58,6 +69,9 @@ export default function ErrorBoundary({ children, section }: Props) {
|
|||
<button onClick={ignoreError}>
|
||||
Ignore error and try to reload app
|
||||
</button>
|
||||
<button onClick={reset}>
|
||||
{confirm ? "Are you sure?" : "Reset all app data"}
|
||||
</button>
|
||||
<button onClick={() => location.reload()}>
|
||||
Refresh page
|
||||
</button>
|
||||
|
|
Loading…
Reference in a new issue