From a36bca2f426af57199d8ae6cc39f8d462cca602b Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Fri, 3 Nov 2023 19:08:04 +0000 Subject: [PATCH] Add sharing buttons in header --- public/images/hackernews.svg | 3 + public/images/reddit.svg | 1 + src/components/RoadmapHeader.astro | 19 ++-- src/components/ShareRoadmapButton.tsx | 135 ++++++++++++++++++++++++++ 4 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 public/images/hackernews.svg create mode 100644 public/images/reddit.svg create mode 100644 src/components/ShareRoadmapButton.tsx diff --git a/public/images/hackernews.svg b/public/images/hackernews.svg new file mode 100644 index 000000000..ae8caccca --- /dev/null +++ b/public/images/hackernews.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/public/images/reddit.svg b/public/images/reddit.svg new file mode 100644 index 000000000..062a4936b --- /dev/null +++ b/public/images/reddit.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/RoadmapHeader.astro b/src/components/RoadmapHeader.astro index ca0bb36c3..3cc9e224c 100644 --- a/src/components/RoadmapHeader.astro +++ b/src/components/RoadmapHeader.astro @@ -10,6 +10,9 @@ import { MarkFavorite } from './FeaturedItems/MarkFavorite'; import { TeamVersions } from './TeamVersions/TeamVersions'; import { CreateVersion } from './CreateVersion/CreateVersion'; import { type RoadmapFrontmatter } from '../lib/roadmap'; +import { ShareRoadmapButton } from './ShareRoadmapButton'; +import { Share2 } from 'lucide-react'; +import ShareIcons from './ShareIcons/ShareIcons.astro'; export interface Props { title: string; @@ -96,6 +99,12 @@ const hasTnsBanner = !!tnsBannerLink; ← + + {isRoadmapReady && ( <> ) } diff --git a/src/components/ShareRoadmapButton.tsx b/src/components/ShareRoadmapButton.tsx new file mode 100644 index 000000000..d70d2661b --- /dev/null +++ b/src/components/ShareRoadmapButton.tsx @@ -0,0 +1,135 @@ +import { Check, Copy, Facebook, Linkedin, Share2, Twitter } from 'lucide-react'; +import { useRef, useState } from 'react'; +import { useOutsideClick } from '../hooks/use-outside-click.ts'; +import { useCopyText } from '../hooks/use-copy-text.ts'; +import { cn } from '../lib/classname.ts'; + +type ShareRoadmapButtonProps = { + description: string; + pageUrl: string; +}; + +export function ShareRoadmapButton(props: ShareRoadmapButtonProps) { + const { description, pageUrl } = props; + + const { isCopied, copyText } = useCopyText(); + + const containerRef = useRef(null); + const [isDropdownOpen, setIsDropdownOpen] = useState(false); + + const twitterUrl = `https://twitter.com/intent/tweet?text=${description}&url=${pageUrl}`; + const fbUrl = `https://www.facebook.com/sharer/sharer.php?quote=${description}&u=${pageUrl}`; + const hnUrl = `https://news.ycombinator.com/submitlink?t=${description}&u=${pageUrl}`; + const redditUrl = `https://www.reddit.com/submit?title=${description}&url=${pageUrl}`; + const linkedinUrl = `https://www.linkedin.com/shareArticle?mini=true&url=${pageUrl}&title=${description}`; + + useOutsideClick(containerRef, () => { + setIsDropdownOpen(false); + }); + + return ( +
+ + + {isDropdownOpen && ( +
+
+ + +
+ +
+ Share on Twitter +
+ +
+ +
+ Facebook +
+ +
+ {'hackernews +
+ Hacker News +
+ +
+ {'reddit +
+ Reddit +
+ +
+ +
+ LinkedIn +
+
+
+ )} +
+ ); +}