diff --git a/src/components/LatestTransactions/LatestTransactions.jsx b/src/components/LatestTransactions/LatestTransactions.jsx index e6a2926..59d8821 100644 --- a/src/components/LatestTransactions/LatestTransactions.jsx +++ b/src/components/LatestTransactions/LatestTransactions.jsx @@ -85,19 +85,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 bf29349..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) @@ -171,7 +208,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 @@ -242,6 +279,12 @@ const toast = useToast()