import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import dynamic from 'next/dynamic'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import {
EmailIcon,
EmailShareButton,
FacebookIcon,
FacebookMessengerIcon,
FacebookMessengerShareButton,
FacebookShareButton,
HatenaIcon,
HatenaShareButton,
InstapaperIcon,
InstapaperShareButton,
LineIcon,
LineShareButton,
LinkedinIcon,
LinkedinShareButton,
LivejournalIcon,
LivejournalShareButton,
MailruIcon,
MailruShareButton,
OKIcon,
OKShareButton,
PinterestIcon,
PinterestShareButton,
PocketIcon,
PocketShareButton,
RedditIcon,
RedditShareButton,
TelegramIcon,
TelegramShareButton,
TumblrIcon,
TumblrShareButton,
TwitterIcon,
TwitterShareButton,
ViberIcon,
ViberShareButton,
VKIcon,
VKShareButton,
WeiboIcon,
WeiboShareButton,
WhatsappIcon,
WhatsappShareButton,
WorkplaceIcon,
WorkplaceShareButton
} from 'react-share'
const QrCode = dynamic(() => import('@/components/QrCode'), { ssr: false })
/**
* @author https://github.com/txs
* @param {*} param0
* @returns
*/
const ShareButtons = ({ post }) => {
const router = useRouter()
const [shareUrl, setShareUrl] = useState(siteConfig('LINK') + router.asPath)
const title = post?.title || siteConfig('TITLE')
const image = post?.pageCover
const tags = post.tags || []
const hashTags = tags.map(tag => `#${tag}`).join(',')
const body =
post?.title + ' | ' + title + ' ' + shareUrl + ' ' + post?.summary
const services = siteConfig('POSTS_SHARE_SERVICES').split(',')
const titleWithSiteInfo = title + ' | ' + siteConfig('TITLE')
const { locale } = useGlobal()
const [qrCodeShow, setQrCodeShow] = useState(false)
const copyUrl = () => {
// 确保 shareUrl 是一个正确的字符串并进行解码
const decodedUrl = decodeURIComponent(shareUrl)
navigator?.clipboard?.writeText(decodedUrl)
alert(locale.COMMON.URL_COPIED + ' \n' + decodedUrl)
}
const openPopover = () => {
setQrCodeShow(true)
}
const closePopover = () => {
setQrCodeShow(false)
}
useEffect(() => {
setShareUrl(window.location.href)
}, [])
return (
<>
{services.map(singleService => {
switch (singleService) {
case 'facebook':
return (
)
case 'messenger':
return (
)
case 'line':
return (
)
case 'reddit':
return (
)
case 'email':
return (
)
case 'twitter':
return (
)
case 'telegram':
return (
)
case 'whatsapp':
return (
)
case 'linkedin':
return (
)
case 'pinterest':
return (
)
case 'vkshare':
return (
)
case 'okshare':
return (
)
case 'tumblr':
return (
)
case 'livejournal':
return (
)
case 'mailru':
return (
)
case 'viber':
return (
)
case 'workplace':
return (
)
case 'weibo':
return (
)
case 'pocket':
return (
)
case 'instapaper':
return (
)
case 'hatena':
return (
)
case 'qq':
return (
)
case 'wechat':
return (
)
case 'link':
return (
)
default:
return <>>
}
})}
>
)
}
export default ShareButtons