Skip to content

Commit 31081c8

Browse files
committed
frontend/user: add display and button for persistent storage
1 parent 4be010a commit 31081c8

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

frontend/src/pages/User.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
*/
1919

2020
import { Component } from "preact";
21-
import { Form, Button, Modal, Card, Container } from "react-bootstrap";
21+
import { Form, Button, Modal, Card, Container, Collapse, Row, Col } from "react-bootstrap";
2222
import { useState } from "preact/hooks";
2323
import { fetchClient, isDebugMode, PASSWORD_PATTERN, concat_salts, generate_hash, generate_random_bytes, get_salt, get_salt_for_user } from "../utils";
2424
import sodium from "libsodium-wrappers";
2525
import { logout } from "../components/Navbar";
2626
import { useTranslation } from "react-i18next";
27-
import { signal } from "@preact/signals";
27+
import { useSignal } from "@preact/signals";
2828
import { PasswordComponent } from "../components/PasswordComponent";
2929
import i18n from "../i18n";
3030
import { showAlert } from "../components/Alert";
@@ -147,7 +147,12 @@ export function User() {
147147
const [newPasswordIsValid, setNewPasswordIsValid] = useState(true);
148148
const [confirmNewPassword, setConfirmNewPassword] = useState("");
149149
const [confirmNewPasswordIsValid, setConfirmNewPasswordIsValid] = useState(true);
150-
const validated = signal(false);
150+
const storagePersisted = useSignal(false);
151+
152+
navigator.storage.persisted().then((persisted) => {
153+
storagePersisted.value = persisted;
154+
});
155+
const validated = useSignal(false);
151156

152157
const handleUpdatePasswordClose = () => setShowPasswordReset(false);
153158
const handleUpdatePasswordShow = () => setShowPasswordReset(true);
@@ -295,6 +300,20 @@ export function User() {
295300
localStorage.removeItem("debugMode");
296301
}
297302
}} />
303+
<Collapse in={isDebugMode.value}>
304+
<div className="mt-3">
305+
<Row>
306+
<Col>{`Storage persisted: ${storagePersisted.value ? "yes" : "no"}`}</Col>
307+
</Row>
308+
<Button
309+
className="mt-2"
310+
variant="secondary"
311+
disabled={storagePersisted.value}
312+
size="sm" onClick={async () => {
313+
storagePersisted.value = await navigator.storage.persist();
314+
}}>Request Storage Persistence</Button>
315+
</div>
316+
</Collapse>
298317
</Card.Body>
299318
<Card.Header className="border-top pb-2">
300319
<h5 className="mb-0">{t("account_actions")}</h5>

0 commit comments

Comments
 (0)