feat: copy url to clipboard on save

This commit is contained in:
Blaster4385 2024-02-22 11:02:06 +05:30
parent 68f473da01
commit 641909aa31

View file

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