File size: 14,276 Bytes
1b72d7e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import copy from 'copy-to-clipboard'
import dynamic from 'next/dynamic'
import { useRouter } from 'next/router'
import { useState } from 'react'
import {
FacebookShareButton,
FacebookIcon,
FacebookMessengerShareButton,
FacebookMessengerIcon,
RedditShareButton,
RedditIcon,
LineShareButton,
LineIcon,
EmailShareButton,
EmailIcon,
TwitterShareButton,
TwitterIcon,
TelegramShareButton,
TelegramIcon,
WhatsappShareButton,
WhatsappIcon,
LinkedinShareButton,
LinkedinIcon,
PinterestShareButton,
PinterestIcon,
VKIcon,
VKShareButton,
OKShareButton,
OKIcon,
TumblrShareButton,
TumblrIcon,
LivejournalIcon,
LivejournalShareButton,
MailruShareButton,
MailruIcon,
ViberIcon,
ViberShareButton,
WorkplaceShareButton,
WorkplaceIcon,
WeiboShareButton,
WeiboIcon,
PocketShareButton,
PocketIcon,
InstapaperShareButton,
InstapaperIcon,
HatenaShareButton,
HatenaIcon
} 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 = siteConfig('LINK') + router.asPath
const title = post.title || siteConfig('TITLE')
const image = post.pageCover
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 = () => {
copy(shareUrl)
alert(locale.COMMON.URL_COPIED)
}
const openPopover = () => {
setQrCodeShow(true)
}
const closePopover = () => {
setQrCodeShow(false)
}
return (
<>
{services.map(singleService => {
if (singleService === 'facebook') {
return (
<FacebookShareButton
key={singleService}
url={shareUrl}
className="mx-1"
>
<FacebookIcon size={32} round />
</FacebookShareButton>
)
}
if (singleService === 'messenger') {
return (
<FacebookMessengerShareButton
key={singleService}
url={shareUrl}
appId={siteConfig('FACEBOOK_APP_ID')}
className="mx-1"
>
<FacebookMessengerIcon size={32} round />
</FacebookMessengerShareButton>
)
}
if (singleService === 'line') {
return (
<LineShareButton
key={singleService}
url={shareUrl}
className="mx-1"
>
<LineIcon size={32} round />
</LineShareButton>
)
}
if (singleService === 'reddit') {
return (
<RedditShareButton
key={singleService}
url={shareUrl}
title={titleWithSiteInfo}
windowWidth={660}
windowHeight={460}
className="mx-1"
>
<RedditIcon size={32} round />
</RedditShareButton>
)
}
if (singleService === 'email') {
return (
<EmailShareButton
key={singleService}
url={shareUrl}
subject={titleWithSiteInfo}
body={body}
className="mx-1"
>
<EmailIcon size={32} round />
</EmailShareButton>
)
}
if (singleService === 'twitter') {
return (
<TwitterShareButton
key={singleService}
url={shareUrl}
title={titleWithSiteInfo}
className="mx-1"
>
<TwitterIcon size={32} round />
</TwitterShareButton>
)
}
if (singleService === 'telegram') {
return (
<TelegramShareButton
key={singleService}
url={shareUrl}
title={titleWithSiteInfo}
className="mx-1"
>
<TelegramIcon size={32} round />
</TelegramShareButton>
)
}
if (singleService === 'whatsapp') {
return (
<WhatsappShareButton
key={singleService}
url={shareUrl}
title={titleWithSiteInfo}
separator=":: "
className="mx-1"
>
<WhatsappIcon size={32} round />
</WhatsappShareButton>
)
}
if (singleService === 'linkedin') {
return (
<LinkedinShareButton
key={singleService}
url={shareUrl}
className="mx-1"
>
<LinkedinIcon size={32} round />
</LinkedinShareButton>
)
}
if (singleService === 'pinterest') {
return (
<PinterestShareButton
key={singleService}
url={shareUrl}
media={image}
className="mx-1"
>
<PinterestIcon size={32} round />
</PinterestShareButton>
)
}
if (singleService === 'vkshare') {
return (
<VKShareButton
key={singleService}
url={shareUrl}
image={image}
className="mx-1"
>
<VKIcon size={32} round />
</VKShareButton>
)
}
if (singleService === 'okshare') {
return (
<OKShareButton
key={singleService}
url={shareUrl}
image={image}
className="mx-1"
>
<OKIcon size={32} round />
</OKShareButton>
)
}
if (singleService === 'tumblr') {
return (
<TumblrShareButton
key={singleService}
url={shareUrl}
title={titleWithSiteInfo}
className="mx-1"
>
<TumblrIcon size={32} round />
</TumblrShareButton>
)
}
if (singleService === 'livejournal') {
return (
<LivejournalShareButton
key={singleService}
url={shareUrl}
title={titleWithSiteInfo}
description={shareUrl}
className="mx-1"
>
<LivejournalIcon size={32} round />
</LivejournalShareButton>
)
}
if (singleService === 'mailru') {
return (
<MailruShareButton
key={singleService}
url={shareUrl}
title={titleWithSiteInfo}
className="mx-1"
>
<MailruIcon size={32} round />
</MailruShareButton>
)
}
if (singleService === 'viber') {
return (
<ViberShareButton
key={singleService}
url={shareUrl}
title={titleWithSiteInfo}
className="mx-1"
>
<ViberIcon size={32} round />
</ViberShareButton>
)
}
if (singleService === 'workplace') {
return (
<WorkplaceShareButton
key={singleService}
url={shareUrl}
quote={titleWithSiteInfo}
className="mx-1"
>
<WorkplaceIcon size={32} round />
</WorkplaceShareButton>
)
}
if (singleService === 'weibo') {
return (
<WeiboShareButton
key={singleService}
url={shareUrl}
title={titleWithSiteInfo}
image={image}
className="mx-1"
>
<WeiboIcon size={32} round />
</WeiboShareButton>
)
}
if (singleService === 'pocket') {
return (
<PocketShareButton
key={singleService}
url={shareUrl}
title={titleWithSiteInfo}
className="mx-1"
>
<PocketIcon size={32} round />
</PocketShareButton>
)
}
if (singleService === 'instapaper') {
return (
<InstapaperShareButton
key={singleService}
url={shareUrl}
title={titleWithSiteInfo}
className="mx-1"
>
<InstapaperIcon size={32} round />
</InstapaperShareButton>
)
}
if (singleService === 'hatena') {
return (
<HatenaShareButton
key={singleService}
url={shareUrl}
title={titleWithSiteInfo}
windowWidth={660}
windowHeight={460}
className="mx-1"
>
<HatenaIcon size={32} round />
</HatenaShareButton>
)
}
if (singleService === 'qq') {
return <button key={singleService} className='cursor-pointer bg-blue-600 text-white rounded-full mx-1'>
<a target='_blank' rel='noreferrer' aria-label="Share by QQ" href={`http://connect.qq.com/widget/shareqq/index.html?url=${shareUrl}&sharesource=qzone&title=${title}&desc=${body}`} >
<i className='fab fa-qq w-8' />
</a>
</button>
}
if (singleService === 'wechat') {
return <button onMouseEnter={openPopover} onMouseLeave={closePopover} aria-label={singleService} key={singleService} className='cursor-pointer bg-green-600 text-white rounded-full mx-1'>
<div id='wechat-button'>
<i className='fab fa-weixin w-8' />
</div>
<div className='absolute'>
<div id='pop' className={(qrCodeShow ? 'opacity-100 ' : ' invisible opacity-0') + ' z-40 absolute bottom-10 -left-10 bg-white shadow-xl transition-all duration-200 text-center'}>
<div className='p-2 mt-1 w-28 h-28'>
{ qrCodeShow && <QrCode value={shareUrl}/> }
</div>
<span className='text-black font-semibold p-1 rounded-t-lg text-sm mx-auto mb-1'>
{locale.COMMON.SCAN_QR_CODE}
</span>
</div>
</div>
</button>
}
if (singleService === 'link') {
return <button aria-label={singleService} key={singleService} className='cursor-pointer bg-yellow-500 text-white rounded-full mx-1'>
<div alt={locale.COMMON.URL_COPIED} onClick={copyUrl} >
<i className='fas fa-link w-8' />
</div>
</button>
}
return <></>
})}
</>
)
}
export default ShareButtons
|