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
+17 -15
View File
@@ -47,21 +47,23 @@ export const ShareDialog = () => {
{
onSuccess: (res) => {
const url = shareUrl(res?.data?.id)
navigator.clipboard
.writeText(url)
.then(() => {
notify('message.shareSuccess', 'info', { url }, false, 0)
})
.catch((err) => {
notify(
translate('message.shareFailure', { url }) + ': ' + err.message,
{
type: 'warning',
multiLine: true,
duration: 0,
}
)
})
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard
.writeText(url)
.then(() => {
notify('message.shareSuccess', 'info', { url }, false, 0)
})
.catch((err) => {
notify(
translate('message.shareFailure', { url }) + ': ' + err.message,
{
type: 'warning',
multiLine: true,
duration: 0,
}
)
})
} else prompt(translate('message.shareCopyToClipboard'), url)
},
onFailure: (error) =>
notify(translate('ra.page.error') + ': ' + error.message, {