web: show error when unlock note password is empty (#10231)

Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
01zulfi
2026-08-13 08:36:12 +05:00
committed by GitHub
parent b181655edc
commit d647eb8187

View File

@@ -33,15 +33,21 @@ type UnlockViewProps = {
}; };
export function UnlockView(props: UnlockViewProps) { export function UnlockView(props: UnlockViewProps) {
const { title, subtitle, buttonTitle, unlock } = props; const { title, subtitle, buttonTitle, unlock } = props;
const [isWrong, setIsWrong] = useState(false); const [errorMessage, setErrorMessage] = useState<string | undefined>(
undefined
);
const [isUnlocking, setIsUnlocking] = useState(false); const [isUnlocking, setIsUnlocking] = useState(false);
const passwordRef = useRef<HTMLInputElement>(null); const passwordRef = useRef<HTMLInputElement>(null);
const submit = useCallback(async () => { const submit = useCallback(async () => {
if (!passwordRef.current?.value) return; const password = passwordRef?.current?.value;
if (!password) {
setErrorMessage(strings.passwordRequired());
return;
}
setIsUnlocking(true); setIsUnlocking(true);
const password = passwordRef.current.value;
try { try {
await unlock(password); await unlock(password);
} catch (e) { } catch (e) {
@@ -49,7 +55,7 @@ export function UnlockView(props: UnlockViewProps) {
e instanceof Error && e instanceof Error &&
e.message.includes("ciphertext cannot be decrypted using that key") e.message.includes("ciphertext cannot be decrypted using that key")
) { ) {
setIsWrong(true); setErrorMessage(strings.passwordIncorrect());
} else { } else {
showToast("error", `${strings.couldNotUnlock()}: ` + e); showToast("error", `${strings.couldNotUnlock()}: ` + e);
console.error(e); console.error(e);
@@ -57,7 +63,7 @@ export function UnlockView(props: UnlockViewProps) {
} finally { } finally {
setIsUnlocking(false); setIsUnlocking(false);
} }
}, [setIsWrong, unlock]); }, [setErrorMessage, unlock]);
return ( return (
<Flex <Flex
@@ -110,12 +116,12 @@ export function UnlockView(props: UnlockViewProps) {
onKeyUp={async (e) => { onKeyUp={async (e) => {
if (e.key === "Enter") { if (e.key === "Enter") {
await submit(); await submit();
} else if (isWrong) { } else if (errorMessage) {
setIsWrong(false); setErrorMessage(undefined);
} }
}} }}
/> />
{isWrong && <ErrorText sx={{ mt: 1 }} error="Wrong password" />} {errorMessage && <ErrorText sx={{ mt: 1 }} error={errorMessage} />}
<Button <Button
mt={3} mt={3}
variant="accent" variant="accent"