feat: add Instagram share button to social share component

This commit is contained in:
fredy.siswanto 2025-03-08 20:53:30 +07:00
parent 333fa32eda
commit 06608c7b5d
2 changed files with 11 additions and 9 deletions

View File

@ -4,7 +4,6 @@ import {
FacebookShareButton, FacebookShareButton,
LinkedinShareButton, LinkedinShareButton,
TwitterShareButton, TwitterShareButton,
InstapaperShareButton,
} from 'react-share' } from 'react-share'
import { FacebookIcon } from '~/components/icons/facebook' import { FacebookIcon } from '~/components/icons/facebook'
@ -28,6 +27,12 @@ export const SocialShareButtons = ({
setShowPopup(true) setShowPopup(true)
setTimeout(() => setShowPopup(false), 2000) setTimeout(() => setShowPopup(false), 2000)
} }
const handleInstagramShare = () => {
const instagramUrl = `https://www.instagram.com/direct/new/?text=${encodeURIComponent(title + ' ' + url)}`
window.open(instagramUrl, '_blank')
}
return ( return (
<div className="flex items-center space-x-2"> <div className="flex items-center space-x-2">
{showPopup && ( {showPopup && (
@ -59,12 +64,9 @@ export const SocialShareButtons = ({
<XIcon className="h-8 w-8 rounded-full bg-gray-400 p-2 sm:h-10 sm:w-10" /> <XIcon className="h-8 w-8 rounded-full bg-gray-400 p-2 sm:h-10 sm:w-10" />
</TwitterShareButton> </TwitterShareButton>
<InstapaperShareButton <button onClick={handleInstagramShare}>
url={url}
title={title}
>
<InstagramIcon className="h-8 w-8 rounded-full bg-gray-400 p-2 sm:h-10 sm:w-10" /> <InstagramIcon className="h-8 w-8 rounded-full bg-gray-400 p-2 sm:h-10 sm:w-10" />
</InstapaperShareButton> </button>
</div> </div>
) )
} }

View File

@ -52,10 +52,10 @@ export const NewsDetailPage = () => {
</p> </p>
</div> </div>
</div> </div>
{/* <IconsSocial className="flex-row" /> */}
<SocialShareButtons <SocialShareButtons
url={`${currentUrl}`} url={`${currentUrl}`}
title={title} title={`${title}`}
/> />
</div> </div>
{/* END TODO: create component for this section */} {/* END TODO: create component for this section */}
@ -78,7 +78,7 @@ export const NewsDetailPage = () => {
<SocialShareButtons <SocialShareButtons
url={`${currentUrl}`} url={`${currentUrl}`}
title={title} title={`${title}`}
/> />
</div> </div>
<div className="flex flex-wrap items-end gap-2"> <div className="flex flex-wrap items-end gap-2">