dont use broken navigator.share on desktop safari
This commit is contained in:
parent
8329da1f56
commit
78520b787b
@ -17,52 +17,42 @@ const referrurl = (ipath, me) => {
|
|||||||
return `${process.env.NEXT_PUBLIC_URL}${path}`
|
return `${process.env.NEXT_PUBLIC_URL}${path}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Share ({ path, title, className = '' }) {
|
async function share (title, url, toaster) {
|
||||||
|
// only use navigator.share on touch devices
|
||||||
|
try {
|
||||||
|
if (navigator?.share &&
|
||||||
|
(navigator?.maxTouchPoints > 0 || navigator?.msMaxTouchPoints > 0)) {
|
||||||
|
await navigator.share({ title, text: '', url })
|
||||||
|
toaster.success('link shared')
|
||||||
|
} else {
|
||||||
|
await copy(url)
|
||||||
|
toaster.success('link copied')
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof DOMException && e.name === 'AbortError') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
toaster.danger('failed to copy link')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Share ({ path, title = '', className = '' }) {
|
||||||
const me = useMe()
|
const me = useMe()
|
||||||
const toaster = useToast()
|
const toaster = useToast()
|
||||||
const url = referrurl(path, me)
|
const url = referrurl(path, me)
|
||||||
|
|
||||||
return !SSR && navigator?.share
|
return (
|
||||||
? (
|
|
||||||
<div className='ms-auto pointer d-flex align-items-center'>
|
<div className='ms-auto pointer d-flex align-items-center'>
|
||||||
<ShareIcon
|
<ShareIcon
|
||||||
width={20} height={20}
|
width={20} height={20}
|
||||||
className={`mx-2 fill-grey theme ${className}`}
|
className={`mx-2 fill-grey theme ${className}`}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
try {
|
await share(title, url, toaster)
|
||||||
await navigator.share({
|
|
||||||
title: title || '',
|
|
||||||
text: '',
|
|
||||||
url
|
|
||||||
})
|
|
||||||
toaster.success('link shared')
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>)
|
</div>
|
||||||
: (
|
)
|
||||||
<Dropdown align='end' className='ms-auto pointer d-flex align-items-center' as='span'>
|
|
||||||
<Dropdown.Toggle variant='success' id='dropdown-basic' as='a'>
|
|
||||||
<ShareIcon width={20} height={20} className={`mx-2 fill-grey theme ${className}`} />
|
|
||||||
</Dropdown.Toggle>
|
|
||||||
<Dropdown.Menu>
|
|
||||||
<Dropdown.Item
|
|
||||||
onClick={async () => {
|
|
||||||
try {
|
|
||||||
await copy(url)
|
|
||||||
toaster.success('link copied')
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
toaster.danger('failed to copy link')
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
copy link
|
|
||||||
</Dropdown.Item>
|
|
||||||
</Dropdown.Menu>
|
|
||||||
</Dropdown>)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CopyLinkDropdownItem ({ item }) {
|
export function CopyLinkDropdownItem ({ item }) {
|
||||||
@ -81,21 +71,7 @@ export function CopyLinkDropdownItem ({ item }) {
|
|||||||
return (
|
return (
|
||||||
<Dropdown.Item
|
<Dropdown.Item
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
try {
|
await share(item.title || '', url, toaster)
|
||||||
if (navigator.share) {
|
|
||||||
await navigator.share({
|
|
||||||
title: item.title || '',
|
|
||||||
text: '',
|
|
||||||
url
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
await copy(url)
|
|
||||||
}
|
|
||||||
toaster.success('link copied')
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
toaster.danger('failed to copy link')
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
copy link
|
copy link
|
||||||
|
Loading…
x
Reference in New Issue
Block a user