Files
lixiyu-net/components/readerpage/ShareButtons.tsx

53 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-12-25 17:21:39 +08:00
import { useToast } from "@/components/ui/use-toast";
import { Config } from "@/data/config";
import { FacebookShareButton, LinkedinShareButton, RedditShareButton, TwitterShareButton } from "next-share";
import { CopyToClipboard } from "react-copy-to-clipboard";
import { FaFacebook, FaLink, FaLinkedin, FaReddit, FaTwitter } from "react-icons/fa6";
export const ShareButtons = (props: {
postId: string;
allowShare?: boolean | null;
subtitle?: string | null;
title: string;
quote?: string | null;
}) => {
2024-04-03 22:08:27 +08:00
const postURL = encodeURI(`https://${Config.SiteDomain}/blog/${props.postId}`);
2023-12-25 17:21:39 +08:00
const copyShareText = `${props.title} ${props.subtitle ? `- ${props.subtitle}` : ""} - ${
Config.Nickname
}'s Blog ${postURL}`;
2023-12-25 17:21:39 +08:00
const { toast } = useToast();
return (
2024-04-03 22:08:27 +08:00
<div className="py-3 flex justify-center space-x-4 text-2xl">
2023-12-25 17:21:39 +08:00
{props.allowShare != false ? (
<>
2024-04-03 22:08:27 +08:00
<FacebookShareButton className="mx-2" quote={props.quote ?? props.title} url={postURL}>
<FaFacebook className="hover:text-blue-500" title="Share to Facebook" />
2023-12-25 17:21:39 +08:00
</FacebookShareButton>
2024-04-03 22:08:27 +08:00
<TwitterShareButton className="mx-2" title={props.title} url={postURL}>
<FaTwitter className="hover:text-sky-500" title="Share to Twitter" />
2023-12-25 17:21:39 +08:00
</TwitterShareButton>
2024-04-03 22:08:27 +08:00
<LinkedinShareButton className="mx-2" title={props.title} url={postURL}>
<FaLinkedin className="hover:text-blue-500" title="Share to Linkedin" />
2023-12-25 17:21:39 +08:00
</LinkedinShareButton>
2024-04-03 22:08:27 +08:00
<RedditShareButton className="mx-2" title={props.title} url={postURL}>
<FaReddit className="hover:text-orange-500" title="Share to Reddit" />
2023-12-25 17:21:39 +08:00
</RedditShareButton>
<CopyToClipboard
onCopy={() => {
toast({ description: "Link is copied successfully" });
}}
text={copyShareText}
>
<FaLink
className="hover:text-gray-500 mx-2 cursor-pointer"
2024-04-03 22:08:27 +08:00
title="Share with the post url and description"
2023-12-25 17:21:39 +08:00
/>
</CopyToClipboard>
</>
) : (
<div className="my-auto text-sm font-bold">{"SHARING IS NOT ALLOWED"}</div>
)}
</div>
);
};