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:
@@ -365,6 +365,7 @@
|
|||||||
"shareOriginalFormat": "Compartilhar no formato original",
|
"shareOriginalFormat": "Compartilhar no formato original",
|
||||||
"shareDialogTitle": "Compartilhar %{resource} '%{name}'",
|
"shareDialogTitle": "Compartilhar %{resource} '%{name}'",
|
||||||
"shareBatchDialogTitle": "Compartilhar 1 %{resource} |||| Compartilhar %{smart_count} %{resource}",
|
"shareBatchDialogTitle": "Compartilhar 1 %{resource} |||| Compartilhar %{smart_count} %{resource}",
|
||||||
|
"shareCopyToClipboard": "Copie para o clipboard: Ctrl+C, Enter",
|
||||||
"shareSuccess": "Link copiado para o clipboard : %{url}",
|
"shareSuccess": "Link copiado para o clipboard : %{url}",
|
||||||
"shareFailure": "Erro ao copiar o link %{url} para o clipboard",
|
"shareFailure": "Erro ao copiar o link %{url} para o clipboard",
|
||||||
"downloadDialogTitle": "Baixar %{resource} '%{name}' (%{size})"
|
"downloadDialogTitle": "Baixar %{resource} '%{name}' (%{size})"
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export const ShareDialog = () => {
|
|||||||
{
|
{
|
||||||
onSuccess: (res) => {
|
onSuccess: (res) => {
|
||||||
const url = shareUrl(res?.data?.id)
|
const url = shareUrl(res?.data?.id)
|
||||||
|
if (navigator.clipboard && window.isSecureContext) {
|
||||||
navigator.clipboard
|
navigator.clipboard
|
||||||
.writeText(url)
|
.writeText(url)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -62,6 +63,7 @@ export const ShareDialog = () => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
} else prompt(translate('message.shareCopyToClipboard'), url)
|
||||||
},
|
},
|
||||||
onFailure: (error) =>
|
onFailure: (error) =>
|
||||||
notify(translate('ra.page.error') + ': ' + error.message, {
|
notify(translate('ra.page.error') + ': ' + error.message, {
|
||||||
|
|||||||
@@ -369,6 +369,7 @@
|
|||||||
"shareOriginalFormat": "Share in original format",
|
"shareOriginalFormat": "Share in original format",
|
||||||
"shareDialogTitle": "Share %{resource} '%{name}'",
|
"shareDialogTitle": "Share %{resource} '%{name}'",
|
||||||
"shareBatchDialogTitle": "Share 1 %{resource} |||| Share %{smart_count} %{resource}",
|
"shareBatchDialogTitle": "Share 1 %{resource} |||| Share %{smart_count} %{resource}",
|
||||||
|
"shareCopyToClipboard": "Copy to clipboard: Ctrl+C, Enter",
|
||||||
"shareSuccess": "URL copied to clipboard: %{url}",
|
"shareSuccess": "URL copied to clipboard: %{url}",
|
||||||
"shareFailure": "Error copying URL %{url} to clipboard",
|
"shareFailure": "Error copying URL %{url} to clipboard",
|
||||||
"downloadDialogTitle": "Download %{resource} '%{name}' (%{size})",
|
"downloadDialogTitle": "Download %{resource} '%{name}' (%{size})",
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const ShareList = (props) => {
|
|||||||
|
|
||||||
const handleShare = (r) => (e) => {
|
const handleShare = (r) => (e) => {
|
||||||
const url = shareUrl(r?.id)
|
const url = shareUrl(r?.id)
|
||||||
|
if (navigator.clipboard && window.isSecureContext) {
|
||||||
navigator.clipboard
|
navigator.clipboard
|
||||||
.writeText(url)
|
.writeText(url)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -48,6 +49,8 @@ const ShareList = (props) => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
} else prompt(translate('message.shareCopyToClipboard'), url)
|
||||||
|
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user