| 1 | "use client"; |
| 2 | |
| 3 | import { Share2 } from "lucide-react"; |
| 4 | import { toast } from "sonner"; |
| 5 | |
| 6 | import { Button } from "@/components/ui/button"; |
| 7 | import { usePresentationState } from "@/states/presentation-state"; |
| 8 | |
| 9 | export function ShareButton() { |
| 10 | const currentPresentationId = usePresentationState( |
| 11 | (state) => state.currentPresentationId, |
| 12 | ); |
| 13 | const shareUrl = currentPresentationId |
| 14 | ? `${window.location.origin}/share/presentation/${currentPresentationId}` |
| 15 | : ""; |
| 16 | |
| 17 | const copyShareLink = async () => { |
| 18 | if (!shareUrl) { |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | await navigator.clipboard.writeText(shareUrl); |
| 23 | toast.success("Presentation link copied"); |
| 24 | }; |
| 25 | |
| 26 | return ( |
| 27 | <Button |
| 28 | variant="ghost" |
| 29 | size="icon" |
| 30 | disabled={!currentPresentationId} |
| 31 | onClick={() => void copyShareLink()} |
| 32 | aria-label={"Copy presentation link"} |
| 33 | > |
| 34 | <Share2 className="size-4" /> |
| 35 | </Button> |
| 36 | ); |
| 37 | } |
| 38 |