From 1b2a99d1f8ed2d35bd1dbe94af9bb71cf2570690 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Mon, 14 Oct 2024 09:00:09 +0500 Subject: [PATCH] mobile: fix copy/share buttons get stuck sometimes with no error thrown --- apps/mobile/app/hooks/use-actions.tsx | 69 +++++++++++++++------------ 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/apps/mobile/app/hooks/use-actions.tsx b/apps/mobile/app/hooks/use-actions.tsx index b02ec059b..717e8de1e 100644 --- a/apps/mobile/app/hooks/use-actions.tsx +++ b/apps/mobile/app/hooks/use-actions.tsx @@ -32,7 +32,7 @@ import Clipboard from "@react-native-clipboard/clipboard"; import React, { useCallback, useEffect, useRef, useState } from "react"; import { InteractionManager, Platform } from "react-native"; import Share from "react-native-share"; -import { db } from "../common/database"; +import { DatabaseLogger, db } from "../common/database"; import { AttachmentDialog } from "../components/attachments"; import { presentDialog } from "../components/dialog/functions"; import NoteHistory from "../components/note-history"; @@ -650,37 +650,43 @@ export const useActions = ({ } async function shareNote() { - if (item.type !== "note") return; + try { + if (item.type !== "note") return; - if (processingId.current === "shareNote") { - ToastManager.show({ - heading: "Please wait...", - message: "We are preparing your note for sharing", - context: "local" - }); - return; - } - if (!checkItemSynced()) return; - if (locked) { - close(); - await sleep(300); - openVault({ - item: item, - novault: true, - locked: true, - share: true, - title: "Share note", - description: "Unlock note to share it." - }); - } else { - processingId.current = "shareNote"; - const convertedText = await convertNoteToText(item); + if (processingId.current === "shareNote") { + ToastManager.show({ + heading: "Please wait...", + message: "We are preparing your note for sharing", + context: "local" + }); + return; + } + if (!checkItemSynced()) return; + if (locked) { + close(); + await sleep(300); + openVault({ + item: item, + novault: true, + locked: true, + share: true, + title: "Share note", + description: "Unlock note to share it." + }); + } else { + processingId.current = "shareNote"; + const convertedText = await convertNoteToText(item); + processingId.current = undefined; + Share.open({ + title: "Share note to", + failOnCancel: false, + message: convertedText || "" + }); + } + } catch (e) { + ToastManager.error(e as Error); + DatabaseLogger.error(e); processingId.current = undefined; - Share.open({ - title: "Share note to", - failOnCancel: false, - message: convertedText || "" - }); } } @@ -768,7 +774,8 @@ export const useActions = ({ }); } } catch (e) { - console.error(e); + processingId.current = undefined; + DatabaseLogger.error(e); ToastManager.error(e as Error); } }