"use client"; import { useState, useRef, useEffect } from "react"; import Image from "next/image"; import { HiX, HiOutlinePaperClip } from "react-icons/hi"; import { toast } from "sonner"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import useAutosizeTextArea from "@/lib/hooks/useAutoSizeTextArea"; import { useModal } from "@/app/_providers/modal/provider"; import { useRouter } from "next/navigation"; import { createEvent } from "@/lib/actions/create"; import { useNDK } from "@/app/_providers/ndk"; import useCurrentUser from "@/lib/hooks/useCurrentUser"; import useImageUpload from "@/lib/hooks/useImageUpload"; type CreateKind1ModalProps = { tags?: string[][]; }; export default function CreateKind1Modal({ tags: initialTags = [], }: CreateKind1ModalProps) { const modal = useModal(); const [isLoading, setIsLoading] = useState(false); const [content, setContent] = useState(""); const { ImageUploadButton, ImagePreview, clear, imagePreview, imageUrl, status: imageStatus, } = useImageUpload("event"); const { ndk } = useNDK(); const { currentUser } = useCurrentUser(); const contentRef = useRef(null); useAutosizeTextArea(contentRef.current, content); async function handleSubmit() { if (!ndk || !currentUser) return; setIsLoading(true); try { const tags: string[][] = initialTags; let noteContent = content; if (imageUrl) { tags.push(["r", imageUrl]); noteContent += `\n${imageUrl}`; } const preEvent = { content: noteContent, pubkey: currentUser.pubkey, tags: tags, kind: 1, }; const event = await createEvent(ndk, preEvent); if (event) { toast.success("Event Created!"); modal?.hide(); } else { toast.error("An error occured"); } } catch (err) { console.log("err", err); } finally { setIsLoading(false); } } return (