feat: copy url to clipboard on save
This commit is contained in:
parent
68f473da01
commit
641909aa31
1 changed files with 26 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue