From 3e7ec08f127fe72e1e25cb63ca40308a5d03e762 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Sat, 23 Nov 2024 16:39:08 +0500 Subject: [PATCH] mobile: fix attachment downloads failing on mobile --- .../common/filesystem/download-attachment.js | 24 + .../app/components/attachments/actions.tsx | 8 +- .../app/components/attachments/index.tsx | 2 +- .../app/components/header/right-menus.tsx | 13 +- .../app/components/selection-header/index.tsx | 23 +- apps/mobile/app/package.json | 2 +- .../app/screens/settings/picker/index.tsx | 4 +- apps/mobile/app/services/event-manager.ts | 1 + apps/mobile/native/webpack.config.js | 2 +- apps/mobile/package-lock.json | 32 +- apps/mobile/package.json | 5 +- .../react-native-material-menu+2.0.0.patch | 19 + ...ative-reanimated-material-menu+2.0.0.patch | 600 ------------------ packages/core/package-lock.json | 25 +- packages/core/package.json | 3 +- packages/core/src/utils/filename.ts | 6 +- 16 files changed, 113 insertions(+), 656 deletions(-) create mode 100644 apps/mobile/patches/react-native-material-menu+2.0.0.patch delete mode 100644 apps/mobile/patches/react-native-reanimated-material-menu+2.0.0.patch diff --git a/apps/mobile/app/common/filesystem/download-attachment.js b/apps/mobile/app/common/filesystem/download-attachment.js index 4893c282f..699eb5fe7 100644 --- a/apps/mobile/app/common/filesystem/download-attachment.js +++ b/apps/mobile/app/common/filesystem/download-attachment.js @@ -224,6 +224,13 @@ export default async function downloadAttachment( } try { + useAttachmentStore.getState().setDownloading({ + groupId: options.groupId || attachment.hash, + current: 0, + total: 1, + filename: attachment.filename + }); + await db .fs() .downloadFile( @@ -231,6 +238,15 @@ export default async function downloadAttachment( attachment.hash, attachment.chunkSize ); + + useAttachmentStore.getState().setDownloading({ + groupId: options.groupId || attachment.hash, + current: 1, + total: 1, + filename: attachment.filename, + success: true + }); + if (!(await exists(attachment.hash))) { DatabaseLogger.log("Attachment does not exist after download."); return; @@ -301,6 +317,14 @@ export default async function downloadAttachment( .unlink(RNFetchBlob.fs.dirs.CacheDir + `/${attachment.hash}_dcache`) .catch(console.log); } + + useAttachmentStore.getState().setDownloading({ + groupId: options.groupId || attachment.hash, + current: 0, + total: 0, + filename: attachment.filename, + success: false + }); DatabaseLogger.error(e); useAttachmentStore.getState().remove(attachment.hash); if (options.throwError) { diff --git a/apps/mobile/app/components/attachments/actions.tsx b/apps/mobile/app/components/attachments/actions.tsx index 41aada248..2e860ecd4 100644 --- a/apps/mobile/app/components/attachments/actions.tsx +++ b/apps/mobile/app/components/attachments/actions.tsx @@ -63,9 +63,11 @@ const Actions = ({ attachment, close, setAttachments, - fwdRef + fwdRef, + context }: { attachment: Attachment; + context: string; setAttachments: (attachments?: VirtualizedGrouping) => void; close?: () => void; fwdRef: RefObject; @@ -79,7 +81,6 @@ const Actions = ({ const [loading, setLoading] = useState<{ name?: string; }>({}); - const actions = [ { name: strings.network.download(), @@ -88,7 +89,7 @@ const Actions = ({ await db.fs().cancel(attachment.hash); useAttachmentStore.getState().remove(attachment.hash); } - downloadAttachment(attachment.hash, false); + downloadAttachment(attachment.hash, context === "global"); fwdRef.current?.hide(); }, icon: "download" @@ -375,6 +376,7 @@ Actions.present = ( setAttachments={set} close={close} attachment={attachment} + context={context || "global"} /> ) }); diff --git a/apps/mobile/app/components/attachments/index.tsx b/apps/mobile/app/components/attachments/index.tsx index 4cea36528..1c7ea9926 100644 --- a/apps/mobile/app/components/attachments/index.tsx +++ b/apps/mobile/app/components/attachments/index.tsx @@ -206,7 +206,7 @@ export const AttachmentDialog = ({ errorOnly={currentFilter === "errors"} attachments={attachments} id={index} - context="global" + context={!isSheet ? "global" : "attachments-list"} /> ); diff --git a/apps/mobile/app/components/header/right-menus.tsx b/apps/mobile/app/components/header/right-menus.tsx index ed7c1e5b4..d884555ae 100644 --- a/apps/mobile/app/components/header/right-menus.tsx +++ b/apps/mobile/app/components/header/right-menus.tsx @@ -19,9 +19,8 @@ along with this program. If not, see . import React, { useRef } from "react"; import { Platform, StyleSheet, View } from "react-native"; -//@ts-ignore import { useThemeColors } from "@notesnook/theme"; -import Menu from "react-native-reanimated-material-menu"; +import { Menu } from "react-native-material-menu"; import { notesnook } from "../../../e2e/test.ids"; import { HeaderRightButton, @@ -97,14 +96,16 @@ export const RightMenus = ({ style={{ borderRadius: 5, backgroundColor: contextMenuColors.primary.background, - marginTop: -40 + marginTop: 35 }} onRequestClose={() => { + //@ts-ignore menuRef.current?.hide(); }} anchor={ { + //@ts-ignore menuRef.current?.show(); }} name="dots-vertical" @@ -116,9 +117,10 @@ export const RightMenus = ({ {headerRightButtons.map((item) => (