aboutsummaryrefslogtreecommitdiff
path: root/client/src/components/Editor/Editor.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/components/Editor/Editor.jsx')
-rw-r--r--client/src/components/Editor/Editor.jsx26
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);