diff options
author | Blaster4385 <blaster4385@tablaster.dev> | 2024-02-22 11:02:06 +0530 |
---|---|---|
committer | Blaster4385 <blaster4385@tablaster.dev> | 2024-04-30 11:10:37 +0530 |
commit | 641909aa31b2683b89fe62a219f7d5f56fbad934 (patch) | |
tree | d54b0bbb2102eeec2f2cab99274f27014381b8ce | |
parent | 68f473da019b4a5330fdfedf63d9c591eb693632 (diff) |
feat: copy url to clipboard on save
-rw-r--r-- | client/src/components/Editor/Editor.jsx | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/client/src/components/Editor/Editor.jsx b/client/src/components/Editor/Editor.jsx index dc7f901..0a78ca8 100644 --- a/client/src/components/Editor/Editor.jsx +++ b/client/src/components/Editor/Editor.jsx @@ -47,6 +47,32 @@ const Editor = () => { }); const data = await response.json(); if (response.ok) { + const isURL = URL_REGEX.test(text); + if (isURL) { + navigator.clipboard.writeText(`${CLIENT_BASE_URL}/r/${data.id}`).then(function () { + alert("Short URL copied to clipboard!"); + }, function (err) { + try { + var successful = document.execCommand('copy'); + alert("Short URL copied to clipboard!"); + } catch (err) { + console.log('Oops, unable to copy'); + } + }); + } + else { + navigator.clipboard.writeText(`${CLIENT_BASE_URL}/r/${data.id}`).then(function () { + navigator.clipboard.writeText(`${CLIENT_BASE_URL}/${data.id}`); + alert("URL copied to clipboard!"); + }, function (err) { + try { + var successful = document.execCommand('copy'); + alert("URL copied to clipboard!"); + } catch (err) { + console.log('Oops, unable to copy'); + } + }); + } navigate(`/${data.id}`); } else { console.error(data); |