Skip to content

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

mobile: show confirm dialog before deleting attachment in attachment manager

Ammar Ahmede381b62e5c20
diff --git a/apps/mobile/app/components/attachments/actions.tsx b/apps/mobile/app/components/attachments/actions.tsx
index 811c08a0e..c156e35e6 100644
--- a/apps/mobile/app/components/attachments/actions.tsx
+++ b/apps/mobile/app/components/attachments/actions.tsx
@@ -177,26 +177,48 @@ const Actions = ({
{
name: strings.delete(),
onPress: async () => {
- const relations = await db.relations.to(attachment, "note").get();
- await db.attachments.remove(attachment.hash, false);
- setAttachments();
- eSendEvent(eDBItemUpdate, attachment.id);
- relations
- .map((relation) => relation.fromId)
- .forEach(async (id) => {
- useTabStore.getState().forEachNoteTab(id, async (tab) => {
- const isFocused = useTabStore.getState().currentTab === tab.id;
- if (isFocused) {
- eSendEvent(eOnLoadNote, {
- item: await db.notes.note(id),
- forced: true
- });
- } else {
- editorController.current.commands.setLoading(true, tab.id);
+ close?.();
+ setTimeout(() => {
+ presentDialog({
+ title: strings.deleteAttachment(),
+ paragraph: strings.deleteAttachmentConfirm(),
+ positiveText: strings.yes(),
+ negativeText: strings.no(),
+ positiveType: "errorShade",
+ positivePress: async () => {
+ try {
+ const relations = await db.relations
+ .to(attachment, "note")
+ .get();
+ await db.attachments.remove(attachment.hash, false);
+ setAttachments();
+ eSendEvent(eDBItemUpdate, attachment.id);
+ relations
+ .map((relation) => relation.fromId)
+ .forEach(async (id) => {
+ useTabStore.getState().forEachNoteTab(id, async (tab) => {
+ const isFocused =
+ useTabStore.getState().currentTab === tab.id;
+ if (isFocused) {
+ eSendEvent(eOnLoadNote, {
+ item: await db.notes.note(id),
+ forced: true
+ });
+ } else {
+ editorController.current.commands.setLoading(
+ true,
+ tab.id
+ );
+ }
+ });
+ });
+ return true;
+ } catch (e) {
+ return false;
}
- });
+ }
});
- close?.();
+ }, 500);
},
icon: "delete-outline"
}
diff --git a/packages/intl/locale/en.po b/packages/intl/locale/en.po
index 311ee8c33..d7d84298e 100644
--- a/packages/intl/locale/en.po
+++ b/packages/intl/locale/en.po
@@ -935,6 +935,10 @@ msgstr "Are you sure you want to clear all logs from {key}?"
msgid "Are you sure you want to clear trash?"
msgstr "Are you sure you want to clear trash?"
+#: src/strings.ts:2666
+msgid "Are you sure you want to delete this attachment?"
+msgstr "Are you sure you want to delete this attachment?"
+
#: src/strings.ts:1542
msgid "Are you sure you want to logout and clear all data stored on THIS DEVICE?"
msgstr "Are you sure you want to logout and clear all data stored on THIS DEVICE?"
@@ -2142,6 +2146,10 @@ msgstr "Delete"
msgid "Delete account"
msgstr "Delete account"
+#: src/strings.ts:2664
+msgid "Delete attachment"
+msgstr "Delete attachment"
+
#: src/strings.ts:1319
msgid "Delete collapsed section"
msgstr "Delete collapsed section"
diff --git a/packages/intl/locale/pseudo-LOCALE.po b/packages/intl/locale/pseudo-LOCALE.po
index 0f076d21c..6e7473b41 100644
--- a/packages/intl/locale/pseudo-LOCALE.po
+++ b/packages/intl/locale/pseudo-LOCALE.po
@@ -935,6 +935,10 @@ msgstr ""
msgid "Are you sure you want to clear trash?"
msgstr ""
+#: src/strings.ts:2666
+msgid "Are you sure you want to delete this attachment?"
+msgstr ""
+
#: src/strings.ts:1542
msgid "Are you sure you want to logout and clear all data stored on THIS DEVICE?"
msgstr ""
@@ -2131,6 +2135,10 @@ msgstr ""
msgid "Delete account"
msgstr ""
+#: src/strings.ts:2664
+msgid "Delete attachment"
+msgstr ""
+
#: src/strings.ts:1319
msgid "Delete collapsed section"
msgstr ""
diff --git a/packages/intl/src/strings.ts b/packages/intl/src/strings.ts
index 0b5621788..3e9657003 100644
--- a/packages/intl/src/strings.ts
+++ b/packages/intl/src/strings.ts
@@ -2660,5 +2660,8 @@ Use this if changes from other devices are not appearing on this device. This wi
passwordRequired: () => t`Password required`,
confirmPasswordRequired: () => t`Confirm password required`,
enterAValidEmailAddress: () => t`Please enter a valid email address`,
- giftCodeRequired: () => t`Gift code required`
+ giftCodeRequired: () => t`Gift code required`,
+ deleteAttachment: () => t`Delete attachment`,
+ deleteAttachmentConfirm: () =>
+ t`Are you sure you want to delete this attachment?`
};