diff --git a/src/routes/$account.chats.$id.lazy.tsx b/src/routes/$account.chats.$id.lazy.tsx index d0e02e8..595f832 100644 --- a/src/routes/$account.chats.$id.lazy.tsx +++ b/src/routes/$account.chats.$id.lazy.tsx @@ -3,7 +3,7 @@ import { cn, getReceivers, groupEventByDate, time, upload } from "@/commons"; import { Spinner } from "@/components/spinner"; import { User } from "@/components/user"; import { CoopIcon } from "@/icons/coop"; -import { ArrowUp, Paperclip } from "@phosphor-icons/react"; +import { ArrowUp, Paperclip, X } from "@phosphor-icons/react"; import * as ScrollArea from "@radix-ui/react-scroll-area"; import { useQuery, useQueryClient } from "@tanstack/react-query"; import { createLazyFileRoute } from "@tanstack/react-router"; @@ -257,16 +257,25 @@ function Form() { const inboxRelays = Route.useLoaderData(); const [newMessage, setNewMessage] = useState(""); + const [attaches, setAttaches] = useState([]); const [isPending, startTransition] = useTransition(); + const remove = (item: string) => { + setAttaches((prev) => prev.filter((att) => att !== item)); + }; + const submit = () => { startTransition(async () => { if (!newMessage.length) return; - const res = await commands.sendMessage(id, newMessage); + const content = `${newMessage}\r\n${attaches.join("\r\n")}`; + const res = await commands.sendMessage(id, content); if (res.status === "error") { - await message(res.error, { title: "Coop", kind: "error" }); + await message(res.error, { + title: "Send mesaage failed", + kind: "error", + }); return; } @@ -275,34 +284,59 @@ function Form() { }; return ( -
+
{!inboxRelays.length ? (
This user doesn't have inbox relays. You cannot send messages to them.
) : ( -
-
- +
+ {attaches?.length ? ( +
+ {attaches.map((item, index) => ( + + ))} +
+ ) : null} +
+
+ +
+ setNewMessage(e.target.value)} + onKeyDown={(e) => { + if (e.key === "Enter") submit(); + }} + className="flex-1 h-9 rounded-full px-3.5 bg-transparent border border-neutral-200 dark:border-neutral-800 focus:outline-none focus:border-blue-500 placeholder:text-neutral-400 dark:placeholder:text-neutral-600" + /> +
- setNewMessage(e.target.value)} - onKeyDown={(e) => { - if (e.key === "Enter") submit(); - }} - className="flex-1 h-9 rounded-full px-3.5 bg-transparent border border-neutral-200 dark:border-neutral-800 focus:outline-none focus:border-blue-500 placeholder:text-neutral-400 dark:placeholder:text-neutral-600" - /> -
)}
@@ -310,8 +344,8 @@ function Form() { } function AttachMedia({ - callback, -}: { callback: Dispatch> }) { + onUpload, +}: { onUpload: Dispatch> }) { const [isPending, startTransition] = useTransition(); const attach = () => { @@ -319,7 +353,7 @@ function AttachMedia({ const file = await upload(); if (file) { - callback((prev) => `${prev} ${file}`); + onUpload((prev) => [...prev, file]); } else { return; }