share catalogue
This commit is contained in:
@@ -19,6 +19,30 @@ const CatalogueItem: FC<Props> = ({ item, refetch }) => {
|
|||||||
|
|
||||||
const deleteCatalog = useDleteCatalog()
|
const deleteCatalog = useDleteCatalog()
|
||||||
|
|
||||||
|
const shareUrl = `${window.location.origin}${Paths.viewer}/${item.id}`
|
||||||
|
|
||||||
|
const handleShare = async () => {
|
||||||
|
try {
|
||||||
|
if (typeof navigator.share === 'function') {
|
||||||
|
await navigator.share({
|
||||||
|
title: item.name,
|
||||||
|
text: item.name,
|
||||||
|
url: shareUrl,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await navigator.clipboard.writeText(shareUrl)
|
||||||
|
toast('لینک در کلیپبورد کپی شد', 'success')
|
||||||
|
} catch (err) {
|
||||||
|
const isAbort =
|
||||||
|
err instanceof DOMException
|
||||||
|
? err.name === 'AbortError'
|
||||||
|
: err instanceof Error && err.name === 'AbortError'
|
||||||
|
if (isAbort) return
|
||||||
|
toast(extractErrorMessage(err, 'امکان اشتراکگذاری وجود ندارد'), 'error')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
deleteCatalog.mutate(item.id, {
|
deleteCatalog.mutate(item.id, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
@@ -55,9 +79,14 @@ const CatalogueItem: FC<Props> = ({ item, refetch }) => {
|
|||||||
<Edit size={18} color='#0047FF' />
|
<Edit size={18} color='#0047FF' />
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
<div className='size-6 bg-[#EAECF4] rounded-md flex justify-center items-center'>
|
<button
|
||||||
|
type='button'
|
||||||
|
onClick={handleShare}
|
||||||
|
className='size-6 bg-[#EAECF4] rounded-md flex justify-center items-center border-0 p-0 cursor-pointer shrink-0'
|
||||||
|
aria-label='اشتراکگذاری'
|
||||||
|
>
|
||||||
<Share size={18} color='#000' />
|
<Share size={18} color='#000' />
|
||||||
</div>
|
</button>
|
||||||
<div className='size-6 bg-[#EAECF4] rounded-md flex justify-center items-center'>
|
<div className='size-6 bg-[#EAECF4] rounded-md flex justify-center items-center'>
|
||||||
<TrashWithConfrim
|
<TrashWithConfrim
|
||||||
onDelete={handleDelete}
|
onDelete={handleDelete}
|
||||||
|
|||||||
Reference in New Issue
Block a user