Add a fallback when the browser does not support copying the share link to clipboard (not a secure origin)

See: https://stackoverflow.com/a/51823007
This commit is contained in:
Deluan
2023-01-30 12:09:01 -05:00
parent 762a1ba998
commit b6fcfa9fc8
4 changed files with 40 additions and 33 deletions
+20 -17
View File
@@ -29,25 +29,28 @@ const ShareList = (props) => {
const handleShare = (r) => (e) => {
const url = shareUrl(r?.id)
navigator.clipboard
.writeText(url)
.then(() => {
notify(translate('message.shareSuccess', { url }), {
type: 'info',
multiLine: true,
duration: 0,
})
})
.catch((err) => {
notify(
translate('message.shareFailure', { url }) + ': ' + err.message,
{
type: 'warning',
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard
.writeText(url)
.then(() => {
notify(translate('message.shareSuccess', { url }), {
type: 'info',
multiLine: true,
duration: 0,
}
)
})
})
})
.catch((err) => {
notify(
translate('message.shareFailure', { url }) + ': ' + err.message,
{
type: 'warning',
multiLine: true,
duration: 0,
}
)
})
} else prompt(translate('message.shareCopyToClipboard'), url)
e.preventDefault()
e.stopPropagation()
}