"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 (
);
}
export function DeleteShareButton({ shareId }: { shareId: string }) {
const router = useRouter();
const [pending, setPending] = useState(false);
async function remove() {
setPending(true);
const result = await deleteShareAction(shareId);
if (!result.success) {
setPending(false);
toast.error(result.error);
return;
}
toast.success("ลบข้อความแชร์แล้ว");
router.push("/share");
}
return (
ลบข้อความแชร์นี้หรือไม่
ข้อความ รูปประกอบ และความคิดเห็นทั้งหมดจะถูกลบถาวร
ยกเลิก
ลบถาวร
);
}
export function DeleteCommentButton({
shareId,
commentId,
}: {
shareId: string;
commentId: string;
}) {
const router = useRouter();
const [pending, setPending] = useState(false);
async function remove() {
setPending(true);
const result = await deleteCommentAction(shareId, commentId);
setPending(false);
if (!result.success) {
toast.error(result.error);
return;
}
toast.success("ลบความคิดเห็นแล้ว");
router.refresh();
}
return (
ลบความคิดเห็นนี้หรือไม่
การลบความคิดเห็นไม่สามารถย้อนกลับได้
ยกเลิก
ลบความคิดเห็น
);
}