diff --git a/src/app/groups/[groupId]/layout.tsx b/src/app/groups/[groupId]/layout.tsx index ca50762..07cf17f 100644 --- a/src/app/groups/[groupId]/layout.tsx +++ b/src/app/groups/[groupId]/layout.tsx @@ -42,7 +42,7 @@ export default async function GroupLayout({
- +
diff --git a/src/app/groups/[groupId]/share-button.tsx b/src/app/groups/[groupId]/share-button.tsx index 808f3a0..fe2e5fb 100644 --- a/src/app/groups/[groupId]/share-button.tsx +++ b/src/app/groups/[groupId]/share-button.tsx @@ -1,4 +1,5 @@ import { CopyButton } from '@/components/copy-button' +import { ShareUrlButton } from '@/components/share-url-button' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { @@ -7,14 +8,15 @@ import { PopoverTrigger, } from '@/components/ui/popover' import { env } from '@/lib/env' +import { Group } from '@prisma/client' import { Share } from 'lucide-react' type Props = { - groupId: string + group: Group } -export function ShareButton({ groupId }: Props) { - const url = `${env.NEXT_PUBLIC_BASE_URL}/groups/${groupId}` +export function ShareButton({ group }: Props) { + const url = `${env.NEXT_PUBLIC_BASE_URL}/groups/${group.id}` return ( @@ -31,6 +33,10 @@ export function ShareButton({ groupId }: Props) {
+

Warning! Every person with the group URL will be able diff --git a/src/components/share-url-button.tsx b/src/components/share-url-button.tsx new file mode 100644 index 0000000..d31aa78 --- /dev/null +++ b/src/components/share-url-button.tsx @@ -0,0 +1,44 @@ +'use client' + +import { Button } from '@/components/ui/button' +import { Share } from 'lucide-react' +import { useEffect, useState } from 'react' + +interface Props { + text: string + url: string +} + +export function ShareUrlButton({ url, text }: Props) { + const canShare = useCanShare(url, text) + if (!canShare) return null + + return ( + + ) +} + +function useCanShare(url: string, text: string) { + const [canShare, setCanShare] = useState(null) + + useEffect(() => { + setCanShare( + navigator.share !== undefined && navigator.canShare({ url, text }), + ) + }, [text, url]) + + return canShare +}