Skip to content

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

mobile: fix defaultValue is used if input is empty in dialog input

Ammar Ahmed03defb3a4835
diff --git a/apps/mobile/app/components/attachments/actions.tsx b/apps/mobile/app/components/attachments/actions.tsx
index 17e95fc24..84a07e74a 100644
--- a/apps/mobile/app/components/attachments/actions.tsx
+++ b/apps/mobile/app/components/attachments/actions.tsx
@@ -161,7 +161,10 @@ const Actions = ({
title: strings.renameFile(),
defaultValue: attachment.filename,
positivePress: async (value) => {
- if (value && value.length > 0) {
+ try {
+ if (!value || !value.trim()) {
+ throw new Error(strings.nameIsRequired());
+ }
await db.attachments.add({
hash: attachment.hash,
filename: value
@@ -173,8 +176,12 @@ const Actions = ({
message: `Attachment renamed to ${value}`,
type: "success"
});
+
+ return true;
+ } catch (e) {
+ ToastManager.error(e as Error, undefined, "local");
+ return false;
}
- return true;
},
positiveText: strings.rename()
});
diff --git a/apps/mobile/app/components/dialog/index.tsx b/apps/mobile/app/components/dialog/index.tsx
index ed1b273b2..b3ebd16d3 100644
--- a/apps/mobile/app/components/dialog/index.tsx
+++ b/apps/mobile/app/components/dialog/index.tsx
@@ -93,7 +93,7 @@ export const Dialog = ({ context = "global" }: { context?: string }) => {
let result = false;
try {
result = await dialogInfo.positivePress(
- values.current.inputValue || dialogInfo.defaultValue,
+ values.current.inputValue,
checked
);
} catch (e) {
diff --git a/apps/mobile/app/hooks/use-actions.tsx b/apps/mobile/app/hooks/use-actions.tsx
index 2e0a685e0..74fc1daf9 100644
--- a/apps/mobile/app/hooks/use-actions.tsx
+++ b/apps/mobile/app/hooks/use-actions.tsx
@@ -368,7 +368,14 @@ export const useActions = ({
inputPlaceholder: strings.name(),
defaultValue: item.title,
positivePress: async (value) => {
- if (!value || value.trim().length === 0) return;
+ if (!value || value.trim().length === 0) {
+ ToastManager.error(
+ new Error(strings.nameIsRequired()),
+ undefined,
+ "local"
+ );
+ return;
+ }
await db.colors.add({
id: item.id,
title: value
diff --git a/apps/mobile/app/screens/settings/functions.js b/apps/mobile/app/screens/settings/functions.js
index 4e03de847..b12e5e70c 100644
--- a/apps/mobile/app/screens/settings/functions.js
+++ b/apps/mobile/app/screens/settings/functions.js
@@ -47,6 +47,14 @@ export async function verifyUser(
negativeText: closeText || strings.cancel(),
positivePress: async (value) => {
try {
+ if (!value || !value.trim()) {
+ ToastManager.error(
+ new Error(strings.passwordNotEntered()),
+ undefined,
+ "local"
+ );
+ return;
+ }
const user = await db.user.getUser();
let verified = !user ? true : await db.user.verifyPassword(value);
if (verified) {
@@ -95,6 +103,14 @@ export async function verifyUserWithApplock() {
keyboardType: keyboardType,
positivePress: async (value) => {
try {
+ if (!value || !value.trim()) {
+ ToastManager.error(
+ new Error(strings.passwordNotEntered()),
+ undefined,
+ "local"
+ );
+ return;
+ }
const verified = await validateAppLockPassword(value);
if (!verified) {
ToastManager.show({
diff --git a/apps/mobile/app/screens/settings/settings-data.tsx b/apps/mobile/app/screens/settings/settings-data.tsx
index 3a8089e2b..8c9b51509 100644
--- a/apps/mobile/app/screens/settings/settings-data.tsx
+++ b/apps/mobile/app/screens/settings/settings-data.tsx
@@ -529,6 +529,14 @@ export const settingsGroups: SettingSection[] = [
positiveText: strings.delete(),
positivePress: async (value) => {
try {
+ if (!value || !value.trim()) {
+ ToastManager.error(
+ new Error(strings.passwordNotEntered()),
+ undefined,
+ "local"
+ );
+ return;
+ }
const verified = await db.user?.verifyPassword(value);
if (verified) {
setTimeout(async () => {
diff --git a/apps/mobile/app/screens/settings/user-section.jsx b/apps/mobile/app/screens/settings/user-section.jsx
index f399ce717..b87cccfb7 100644
--- a/apps/mobile/app/screens/settings/user-section.jsx
+++ b/apps/mobile/app/screens/settings/user-section.jsx
@@ -201,6 +201,14 @@ const SettingsUserSection = ({ item }) => {
inputPlaceholder: strings.enterFullName(),
defaultValue: userProfile?.fullName,
positivePress: async (value) => {
+ if (!value || !value.trim()) {
+ ToastManager.error(
+ new Error(strings.nameIsRequired()),
+ undefined,
+ "local"
+ );
+ return;
+ }
db.settings
.setProfile({
fullName: value
diff --git a/apps/mobile/app/utils/unlock-vault.ts b/apps/mobile/app/utils/unlock-vault.ts
index 75ae34d8d..92577f154 100644
--- a/apps/mobile/app/utils/unlock-vault.ts
+++ b/apps/mobile/app/utils/unlock-vault.ts
@@ -65,6 +65,14 @@ export async function unlockVault({
paragraph: paragraph,
inputPlaceholder: strings.enterPassword(),
positivePress: async (value) => {
+ if (!value || !value.trim()) {
+ ToastManager.error(
+ new Error(strings.passwordNotEntered()),
+ undefined,
+ "local"
+ );
+ return;
+ }
const unlocked = await db.vault.unlock(value);
if (!unlocked) {
ToastManager.show({
diff --git a/packages/intl/locale/en.po b/packages/intl/locale/en.po
index 6499ba0ea..09fe8f1e1 100644
--- a/packages/intl/locale/en.po
+++ b/packages/intl/locale/en.po
@@ -4034,6 +4034,10 @@ msgstr "Multi-layer encryption to most important notes"
msgid "Name"
msgstr "Name"
+#: src/strings.ts:2669
+msgid "Name is required."
+msgstr "Name is required."
+
#: src/strings.ts:1688
msgid "Native high-performance encryption"
msgstr "Native high-performance encryption"
diff --git a/packages/intl/locale/pseudo-LOCALE.po b/packages/intl/locale/pseudo-LOCALE.po
index add9f914c..ab3f66ba2 100644
--- a/packages/intl/locale/pseudo-LOCALE.po
+++ b/packages/intl/locale/pseudo-LOCALE.po
@@ -4014,6 +4014,10 @@ msgstr ""
msgid "Name"
msgstr ""
+#: src/strings.ts:2669
+msgid "Name is required."
+msgstr ""
+
#: src/strings.ts:1688
msgid "Native high-performance encryption"
msgstr ""
diff --git a/packages/intl/src/strings.ts b/packages/intl/src/strings.ts
index 472ef36c3..6bfe069ec 100644
--- a/packages/intl/src/strings.ts
+++ b/packages/intl/src/strings.ts
@@ -2665,5 +2665,6 @@ Use this if changes from other devices are not appearing on this device. This wi
deleteAttachmentConfirm: () =>
t`Are you sure you want to delete this attachment?`,
attachmentDeleted: () => t`Attachment deleted`,
- titleIsRequired: () => t`Title is required`
+ titleIsRequired: () => t`Title is required`,
+ nameIsRequired: () => t`Name is required.`
};