Skip to content

Commit 471f45e

Browse files
committed
feat: add recovery mode in case of database corruption
1 parent 26e2813 commit 471f45e

2 files changed

Lines changed: 96 additions & 7 deletions

File tree

src/index.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/* @refresh reload */
22
import "solid-devtools";
3+
import { ErrorBoundary, render } from "solid-js/web";
34
import { AppRoutes } from "./app-routes";
45
import { PopupObs } from "./domains/obs/popup-obs";
6+
import { Recovery } from "./views/recovery";
57
import { Route } from "@solidjs/router";
68
import { assert } from "./domains/_core/utils/assert";
79
import { injectFavicon } from "./domains/_core/utils/favicon";
810
import { injectGlobalStyles } from "./domains/ui/global-styles";
911
import logo from "./assets/icons/original-no-background-stylized.png";
10-
import { render } from "solid-js/web";
1112
import { useRouter } from "./domains/_core/compositions/use-router";
1213

1314
const root = document.querySelector("#root");
@@ -26,11 +27,13 @@ assert(root, "Root element not found.");
2627
render(() => {
2728
const { Router } = useRouter();
2829
return (
29-
<Router>
30-
<Route path="obs" component={PopupObs} />
31-
<Route path="*">
32-
<AppRoutes />
33-
</Route>
34-
</Router>
30+
<ErrorBoundary fallback={(error: Error) => <Recovery error={error} />}>
31+
<Router>
32+
<Route path="obs" component={PopupObs} />
33+
<Route path="*">
34+
<AppRoutes />
35+
</Route>
36+
</Router>
37+
</ErrorBoundary>
3538
);
3639
}, root);

src/views/recovery.tsx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import type { Component } from "solid-js";
2+
import { SymbolButton } from "../domains/ui/components/symbol-button";
3+
import { ValibotImportButton } from "../domains/database/components/valibot-import-button/valibot-import-button";
4+
import { css } from "@emotion/css";
5+
import { useDatabases } from "../domains/database/compositions/use-databases";
6+
7+
const sCode = css({
8+
whiteSpace: "pre",
9+
});
10+
11+
interface RecoveryProps {
12+
error: Error;
13+
}
14+
15+
export const Recovery: Component<RecoveryProps> = (props) => {
16+
const databases = useDatabases();
17+
18+
return (
19+
<>
20+
<h1>Something went wrong.</h1>
21+
22+
<details>
23+
<summary>
24+
<span>Error: {props.error.toString()}</span>
25+
</summary>
26+
<code class={sCode}>{JSON.stringify(props.error, undefined, 2)}</code>
27+
</details>
28+
29+
<p>Most probably the database is corrupted. Try to recover by following these steps.</p>
30+
<dl>
31+
<dt>Step 1</dt>
32+
<dd>
33+
<p>Export your database.</p>
34+
{/*This component must be changed when rebasing release on dev*/}
35+
<SymbolButton symbol="📤" onClick={databases.download}>
36+
Export
37+
</SymbolButton>
38+
</dd>
39+
<dt>Step 2</dt>
40+
<dd>
41+
<p>Import the database you just exported to get some hints about faulty attempt(s).</p>
42+
<p>
43+
<ValibotImportButton symbol="📥" onClick={databases.restore}>
44+
Import
45+
</ValibotImportButton>
46+
</p>
47+
</dd>
48+
<dt>Step 3</dt>
49+
<dd>
50+
<p>
51+
Open the JSON file with a code or text editor, and remove the faulty attempt(s). Then import again your
52+
database.
53+
</p>
54+
<p>
55+
<ValibotImportButton symbol="📥" onClick={databases.restore}>
56+
Import
57+
</ValibotImportButton>
58+
</p>
59+
</dd>
60+
61+
<dt>Step 4</dt>
62+
<dd>
63+
<p>
64+
The import was successful? Just{" "}
65+
<a
66+
href={location.href}
67+
onClick={() => {
68+
location.reload();
69+
}}
70+
>
71+
reload
72+
</a>{" "}
73+
the page.
74+
</p>
75+
<p>
76+
This is too technical and you got lost? You can find me (@Lukino) on{" "}
77+
<a target="_blank" href="https://discord.gg/6gDAPxvqh7">
78+
Mario Kart World Time Trials
79+
</a>{" "}
80+
discord. I would be happy to help you.
81+
</p>
82+
</dd>
83+
</dl>
84+
</>
85+
);
86+
};

0 commit comments

Comments
 (0)