mobile: fix copy/share buttons get stuck sometimes with no error thrown

This commit is contained in:
Ammar Ahmed
2024-10-14 09:00:09 +05:00
parent 05df9b77ed
commit 1b2a99d1f8

View File

@@ -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);
}
}