Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: show inline password error on note unlock instead of toast

kashaf-ansari-deva6a74b924ee8
diff --git a/apps/mobile/app/screens/editor/index.tsx b/apps/mobile/app/screens/editor/index.tsx
index 896399e31..b3e95a27d 100755
--- a/apps/mobile/app/screens/editor/index.tsx
+++ b/apps/mobile/app/screens/editor/index.tsx
@@ -64,6 +64,7 @@ import { strings } from "@notesnook/intl";
import { i18n } from "@lingui/core";
import { useVaultStatus } from "../../hooks/use-vault-status";
import { useSettingStore } from "../../stores/use-setting-store";
+import { NativeEvents } from "@notesnook/editor-mobile/src/utils/native-events";
const style: ViewStyle = {
height: "100%",
@@ -268,17 +269,22 @@ const useLockedNoteHandler = () => {
const onSubmit = async ({
password,
- biometrics: enrollBiometrics
+ biometrics: enrollBiometrics,
+ resolverId
}: {
password: string;
biometrics?: boolean;
+ resolverId?: string;
}) => {
if (!tabRef.current?.session?.noteId || !tabRef.current) return;
+
if (!password || password.trim().length === 0) {
- ToastManager.show({
- heading: strings.passwordNotEntered(),
- type: "error"
- });
+ if (resolverId) {
+ editorController.current?.postMessage(NativeEvents.resolve, {
+ resolverId,
+ data: { success: false, error: strings.passwordNotEntered() }
+ });
+ }
return;
}
@@ -287,6 +293,7 @@ const useLockedNoteHandler = () => {
tabRef.current?.session?.noteId,
password
);
+
if (enrollBiometrics && note) {
try {
const unlocked = await db.vault.unlock(password);
@@ -298,7 +305,6 @@ const useLockedNoteHandler = () => {
type: "success",
context: "global"
});
-
const biometry = await BiometricService.isBiometryAvailable();
const fingerprint = await BiometricService.hasInternetCredentials();
useTabStore.setState({
@@ -306,22 +312,24 @@ const useLockedNoteHandler = () => {
biometryEnrolled: !!fingerprint
});
syncTabs();
- } catch (e) {
- ToastManager.show({
- heading: strings.passwordIncorrect(),
- type: "error"
- });
- }
+ } catch (e) {}
}
- eSendEvent(eOnLoadNote, {
- item: note,
- refresh: true
- });
+
+ if (resolverId) {
+ editorController.current?.postMessage(NativeEvents.resolve, {
+ resolverId,
+ data: { success: true }
+ });
+ }
+
+ eSendEvent(eOnLoadNote, { item: note, refresh: true });
} catch (e) {
- ToastManager.show({
- heading: strings.passwordIncorrect(),
- type: "error"
- });
+ if (resolverId) {
+ editorController.current?.postMessage(NativeEvents.resolve, {
+ resolverId,
+ data: { success: false, error: strings.passwordIncorrect() }
+ });
+ }
}
};
diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx b/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx
index 55d37e9fa..330ff3991 100644
--- a/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx
+++ b/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx
@@ -721,7 +721,10 @@ export const useEditorEvents = (
}
case EditorEvents.unlock: {
- eSendEvent(eUnlockWithPassword, editorMessage.value);
+ eSendEvent(eUnlockWithPassword, {
+ ...editorMessage.value,
+ resolverId: editorMessage.resolverId
+ });
break;
}
diff --git a/packages/editor-mobile/src/components/editor.tsx b/packages/editor-mobile/src/components/editor.tsx
index 697893636..2bcb73829 100644
--- a/packages/editor-mobile/src/components/editor.tsx
+++ b/packages/editor-mobile/src/components/editor.tsx
@@ -65,6 +65,7 @@ const Tiptap = ({
const tab = useTabContext();
const isFocused = useTabStore((state) => state.currentTab === tab?.id);
const [tick, setTick] = useState(0);
+ const [passwordError, setPasswordError] = useState<string | null>(null);
const containerRef = useRef<HTMLDivElement>(null);
const noteStateUpdateTimer = useRef<NodeJS.Timeout>();
const tabRef = useRef<TabItem>(tab);
@@ -660,15 +661,31 @@ const Tiptap = ({
</p>
<form
- onSubmit={(e) => {
+ onSubmit={async (e) => {
e.preventDefault();
const data = new FormData(e.currentTarget);
const password = data.get("password");
+ if (!password) {
+ setPasswordError(strings.enterPassword());
+ return;
+ }
+
+ setPasswordError(null);
const biometrics = data.get("enrollBiometrics");
- post("editor-events:unlock", {
- password,
- biometrics: biometrics === "on" ? true : false
- });
+
+ const result = await postAsyncWithTimeout(
+ EditorEvents.unlock,
+ {
+ password,
+ biometrics: biometrics === "on"
+ }
+ );
+
+ if (result && !result.success) {
+ setPasswordError(
+ result.error || strings.passwordIncorrect()
+ );
+ }
}}
style={{
display: "flex",
@@ -683,7 +700,9 @@ const Tiptap = ({
ref={controller.passwordInputRef}
name="password"
type="password"
- required
+ onChange={() => {
+ if (passwordError) setPasswordError(null);
+ }}
style={{
boxSizing: "border-box",
width: 300,
@@ -698,6 +717,19 @@ const Tiptap = ({
color: colors.primary.paragraph
}}
/>
+ {passwordError ? (
+ <p
+ style={{
+ color: colors.error.paragraph,
+ fontSize: "0.8rem",
+ margin: 0,
+ width: 300,
+ userSelect: "none"
+ }}
+ >
+ {passwordError}
+ </p>
+ ) : null}
<button
className="unlock-note"