"use client"; import { useState, useTransition } from "react"; import { signIn } from "next-auth/react"; import { useRouter } from "next/navigation"; import { Clipboard, Link2, LogIn, MessageSquare, Trash2 } from "lucide-react"; import { toast } from "sonner"; import { createCommentAction, deleteCommentAction, deleteShareAction, } from "@/app/actions/share"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Button } from "@/components/ui/button"; import { Field, FieldDescription, FieldError, FieldLabel, } from "@/components/ui/field"; import { Spinner } from "@/components/ui/spinner"; import { Textarea } from "@/components/ui/textarea"; import { MAX_SHARE_COMMENT_LENGTH } from "@/lib/share/limits"; import { getShareContentForClipboard } from "@/lib/share/copy"; export function CopyShareActions() { async function copyText() { const content = getShareContentForClipboard((id) => document.getElementById(id), ); if (content === null) return; await navigator.clipboard.writeText(content); toast.success("คัดลอกข้อความแล้ว"); } async function copyLink() { await navigator.clipboard.writeText(window.location.href); toast.success("คัดลอกลิงก์แล้ว"); } return (
); } export function CommentComposer({ shareId, authenticated, }: { shareId: string; authenticated: boolean; }) { const router = useRouter(); const [body, setBody] = useState(""); const [error, setError] = useState(null); const [pending, startTransition] = useTransition(); if (!authenticated) { return ( ); } return (
{ event.preventDefault(); setError(null); startTransition(async () => { const result = await createCommentAction(shareId, body); if (!result.success) { setError(result.error); return; } setBody(""); toast.success("เพิ่มความคิดเห็นแล้ว"); router.refresh(); }); }} > แสดงความคิดเห็น