Files
Trilium/apps/client/src/widgets/dialogs/protected_session_password.tsx

52 lines
1.9 KiB
TypeScript

import { useRef, useState } from "preact/hooks";
import { closeActiveDialog } from "../../services/dialog";
import { t } from "../../services/i18n";
import Button from "../react/Button";
import FormTextBox from "../react/FormTextBox";
import Modal from "../react/Modal";
import ReactBasicWidget from "../react/ReactBasicWidget";
import protected_session from "../../services/protected_session";
import useTriliumEvent from "../react/hooks";
function ProtectedSessionPasswordDialogComponent() {
const [ shown, setShown ] = useState(false);
const [ password, setPassword ] = useState("");
const inputRef = useRef<HTMLInputElement>(null);
useTriliumEvent("showProtectedSessionPasswordDialog", () => setShown(true));
return (
<Modal
className="protected-session-password-dialog"
title={t("protected_session_password.modal_title")}
size="md"
helpPageId="bwg0e8ewQMak"
footer={<Button text={t("protected_session_password.start_button")} />}
onSubmit={() => protected_session.setupProtectedSession(password)}
onShown={() => inputRef.current?.focus()}
onHidden={() => setShown(false)}
show={shown}
>
<label htmlFor="protected-session-password" className="col-form-label">{t("protected_session_password.form_label")}</label>
<FormTextBox
id="protected-session-password"
name="protected-session-password"
type="password"
autoComplete="current-password"
onChange={setPassword}
/>
</Modal>
)
}
export default class ProtectedSessionPasswordDialog extends ReactBasicWidget {
get component() {
return <ProtectedSessionPasswordDialogComponent />;
}
closeProtectedSessionPasswordDialogEvent() {
closeActiveDialog();
}
}