Skip to content

Commit

Permalink
update share url to localized version
Browse files Browse the repository at this point in the history
  • Loading branch information
the-kwisatz-haderach committed May 19, 2024
1 parent 8f5610a commit 9c97c4f
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions components/Obituary/components/ObituaryLarge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,40 @@ export const ObituaryLarge: ObituaryRenderer = ({
} = data
const { t } = useTranslation()

const createShareUrl = useCallback(() => {
const translatedType = t(type)
if (translatedType && _id) {
return `${window.location.origin}/${translatedType}/${_id}`
}
return ''
}, [_id, t, type])

const shareToFacebook = useCallback(async () => {
const shareUrl = `${window.location.origin}/${type}/${_id}`
window?.FB?.ui({
display: 'popup',
method: 'share',
href: shareUrl,
})
// if (navigator?.canShare?.()) {
// await navigator.share({
// title: 'Herro',
// text: 'Learn web development on MDN!',
// url: 'https://developer.mozilla.org',
// })
// }
}, [_id, type])
const shareUrl = createShareUrl()
if (shareUrl) {
window?.FB?.ui({
display: 'popup',
method: 'share',
href: shareUrl,
})
}
}, [createShareUrl])

const share = useCallback(async () => {
const url = `${window.location.origin}/${type}/${_id}`
try {
await navigator?.share?.({ url })
} catch {}
}, [_id, type])
const shareUrl = createShareUrl()
if (shareUrl) {
try {
await navigator?.share?.({ url: shareUrl })
} catch {}
}
}, [createShareUrl])

useEffect(() => {
const url = `${window.location.origin}/${type}/${_id}`
if (navigator?.canShare?.({ url })) {
const shareUrl = createShareUrl()
if (shareUrl && navigator?.canShare?.({ url: shareUrl })) {
setCanShare(true)
}
}, [_id, type])
}, [createShareUrl])

return (
<>
Expand Down

0 comments on commit 9c97c4f

Please sign in to comment.