From 949ff91d26159c5a50a85d968a3ab75bb5639f60 Mon Sep 17 00:00:00 2001 From: "Siddhesh.More" Date: Wed, 30 Oct 2024 19:05:35 +0530 Subject: [PATCH 1/2] update --- src/pages/Home.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index bf29349..c10376a 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -171,7 +171,7 @@ const toast = useToast() _focus={{ opacity:1, outline:'none', bg:colorMode === "light" ? "#4023A6" : "#565252" }} _active={{ opacity:0.9, outline:'none', bg:colorMode === "light" ? "#4023A6" : "#565252" }} color={'#fff'} - + isLoading={isLoading} onClick={handleGenrateShortURL} > Generate short url From bdf71c55d17d834d36ae5a979f228cdb93ef76d0 Mon Sep 17 00:00:00 2001 From: "Siddhesh.More" Date: Wed, 30 Oct 2024 19:16:32 +0530 Subject: [PATCH 2/2] copy mac fixed --- .../LatestTransactions/LatestTransactions.jsx | 50 ++++++++++++-- src/pages/Home.jsx | 69 +++++++++++++++---- 2 files changed, 99 insertions(+), 20 deletions(-) diff --git a/src/components/LatestTransactions/LatestTransactions.jsx b/src/components/LatestTransactions/LatestTransactions.jsx index 6708700..2ee64f1 100644 --- a/src/components/LatestTransactions/LatestTransactions.jsx +++ b/src/components/LatestTransactions/LatestTransactions.jsx @@ -83,19 +83,55 @@ const LatestTransactions = () => { setTotalItems(transCount?.data?.transactionCount); }, [transCount]); + // function copyToClipboard(text) { + // navigator.clipboard + // .writeText(text) + // .then(() => { + // toast({ + // render: () => ( + // + // ), + // }); + // }) + // .catch((err) => { + // console.error("Failed to copy text: ", err); + // }); + // } + + + function copyToClipboard(text) { - navigator.clipboard - .writeText(text) - .then(() => { + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard + .writeText(text) + .then(() => { + toast({ + render: () => ( + + ), + }); + }) + .catch((err) => { + console.error("Failed to copy text: ", err); + }); + } else { + // Fallback method for unsupported browsers + const textArea = document.createElement("textarea"); + textArea.value = text; + document.body.appendChild(textArea); + textArea.select(); + try { + document.execCommand("copy"); toast({ render: () => ( ), }); - }) - .catch((err) => { - console.error("Failed to copy text: ", err); - }); + } catch (err) { + console.error("Fallback: Failed to copy text: ", err); + } + document.body.removeChild(textArea); + } } const handleRefreshClick = () => { diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index c10376a..d0b0877 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -60,27 +60,64 @@ const toast = useToast() // console.error("Error generating short URL:", error); // } // }; - function copyToClipboard(text) { - if (!navigator.clipboard) { - console.error("Clipboard API is not available."); - return; - } + - navigator.clipboard - .writeText(text) - .then(() => { + // function copyToClipboard(text) { + // if (!navigator.clipboard) { + // console.error("Clipboard API is not available."); + // return; + // } + + // navigator.clipboard + // .writeText(text) + // .then(() => { + // toast({ + // render: () => ( + // + // ), + // }); + // setIsCopy(true) + // }) + // .catch((err) => { + // console.error("Failed to copy text: ", err); + // }); + // } + + function copyToClipboard(text) { + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard + .writeText(text) + .then(() => { + toast({ + render: () => ( + + ), + }); + }) + .catch((err) => { + console.error("Failed to copy text: ", err); + }); + } else { + // Fallback method for unsupported browsers + const textArea = document.createElement("textarea"); + textArea.value = text; + document.body.appendChild(textArea); + textArea.select(); + try { + document.execCommand("copy"); toast({ render: () => ( ), }); - setIsCopy(true) - }) - .catch((err) => { - console.error("Failed to copy text: ", err); - }); + } catch (err) { + console.error("Fallback: Failed to copy text: ", err); + } + document.body.removeChild(textArea); + } } + const handleGenrateShortURL = async () => { setLinkVisible(true) @@ -242,6 +279,12 @@ const toast = useToast()