文件
mynode/packages/app-desktop/gui/ConfigScreen/controls/useNoteLockMode.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

51 行
1.3 KiB
TypeScript

import { useCallback, useEffect, useState } from 'react';
export enum ActionMode {
Collapsed = 'collapsed',
Create = 'create',
Change = 'change',
Reset = 'reset',
}
const useNoteLockMode = (hasKey: boolean) => {
const [mode, setMode] = useState<ActionMode>(hasKey ? ActionMode.Collapsed : ActionMode.Create);
const [currentPassword, setCurrentPassword] = useState('');
const [password, setPassword] = useState('');
const [passwordRepeat, setPasswordRepeat] = useState('');
const [error, setError] = useState('');
const clearForm = useCallback(() => {
setCurrentPassword('');
setPassword('');
setPasswordRepeat('');
setError('');
}, []);
const onModeChange = useCallback((newMode: ActionMode) => {
setMode(newMode);
clearForm();
}, [clearForm]);
// The key can also appear or disappear through sync while this screen is open;
// clear any drafted input along with the mode switch.
useEffect(() => {
if (hasKey && mode === ActionMode.Create) onModeChange(ActionMode.Collapsed);
if (!hasKey && mode !== ActionMode.Create) onModeChange(ActionMode.Create);
}, [hasKey, mode, onModeChange]);
return {
mode,
onModeChange,
currentPassword,
setCurrentPassword,
password,
setPassword,
passwordRepeat,
setPasswordRepeat,
error,
setError,
};
};
export default useNoteLockMode;