Skip to content

Commit

Permalink
fix: Use navigator.clipboard instead of copy-text-to-clipboard
Browse files Browse the repository at this point in the history
copy-text-to-clipboard use deprecated command.exec which does not
work anymore on some desktop browser.
  • Loading branch information
zatteo committed Feb 1, 2024
1 parent 6011028 commit 6727c26
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/cozy-sharing/src/components/ShareByLink.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import copy from 'copy-text-to-clipboard'
import PropTypes from 'prop-types'
import React, { useState, useEffect, useCallback } from 'react'

Expand All @@ -25,20 +24,23 @@ const ShareByLink = ({ link, document, documentType, onEnable }) => {
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false)

const copyLinkToClipboard = useCallback(
({ isAutomaticCopy }) => {
if (copy(link)) {
async ({ isAutomaticCopy }) => {
try {
await navigator.clipboard.writeText(link)
setAlert({
open: true,
severity: 'success',
message: t(`${documentType}.share.shareByLink.copied`)
})
} else if (!isAutomaticCopy) {
// In case of automatic copy, the browser can block the copy request. This is not shown to the user since it is expected and can be circumvented by clicking directly on the copy link
setAlert({
open: true,
severity: 'error',
message: t(`${documentType}.share.shareByLink.failed`)
})
} catch {
if (!isAutomaticCopy) {
// In case of automatic copy, the browser can block the copy request. This is not shown to the user since it is expected and can be circumvented by clicking directly on the copy link
setAlert({
open: true,
severity: 'error',
message: t(`${documentType}.share.shareByLink.failed`)
})
}
}
},
[documentType, link, t]
Expand Down

0 comments on commit 6727c26

Please sign in to comment.