diff --git a/AgentCompany-New/src/renderer/src/pages/ChatPage.tsx b/AgentCompany-New/src/renderer/src/pages/ChatPage.tsx index 17edd790..9f67a238 100644 --- a/AgentCompany-New/src/renderer/src/pages/ChatPage.tsx +++ b/AgentCompany-New/src/renderer/src/pages/ChatPage.tsx @@ -1,7 +1,7 @@ import { useState, type FormEvent, type ReactNode } from "react"; import { Avatar, Button, Field, Icon, IconButton } from "../shared/ui"; import { Dialog } from "../shared/Dialog"; -import type { ChatAttachmentRecord, ChatSpaceRecord, FileObjectRecord } from "../../../shared/domain"; +import type { ChatAttachmentRecord, ChatSpaceRecord, ChatThreadRecord, FileObjectRecord } from "../../../shared/domain"; import type { PageProps } from "./types"; import { activeOrgId } from "./types"; @@ -21,9 +21,14 @@ export function ChatPage({ snapshot, actions }: PageProps) { const files = snapshot.files.filter((item) => item.orgId === orgId); const [spaceId, setSpaceId] = useState(spaces[0]?.id ?? ""); const [spaceOpen, setSpaceOpen] = useState(false); + const [selectedThreadId, setSelectedThreadId] = useState(null); const activeSpace = spaces.find((space) => space.id === spaceId) ?? spaces[0]; if (!activeSpace) throw new Error("At least one chat space is required."); const messages = snapshot.chatMessages.filter((item) => item.orgId === orgId && item.spaceId === activeSpace.id); + const rootMessages = messages.filter((m) => m.threadId === null); + const threads = snapshot.chatThreads.filter((t) => t.spaceId === activeSpace.id); + const selectedThread = threads.find((t) => t.id === selectedThreadId) ?? null; + const threadMessages = selectedThread ? messages.filter((m) => m.threadId === selectedThread.id) : []; const sender = employees[0]; const submit = (event: FormEvent) => { @@ -45,6 +50,24 @@ export function ChatPage({ snapshot, actions }: PageProps) { })); }; + const submitReply = (event: FormEvent) => { + event.preventDefault(); + if (!selectedThread || !sender) return; + const form = new FormData(event.currentTarget); + const bodyMd = messageBody(form); + if (!bodyMd) return; + event.currentTarget.reset(); + void actions.run(() => window.agentCompany.sendMessage({ + orgId, + spaceId: activeSpace.id, + threadId: selectedThread.id, + senderType: "employee", + senderId: sender.id, + bodyMd, + attachmentFileIds: [], + })); + }; + const createSpace = (event: FormEvent) => { event.preventDefault(); const form = new FormData(event.currentTarget); @@ -84,8 +107,9 @@ export function ChatPage({ snapshot, actions }: PageProps) { ))} +
-
+
{activeSpace.name}
@@ -94,20 +118,26 @@ export function ChatPage({ snapshot, actions }: PageProps) {
- {messages.length === 0 ? ( + {rootMessages.length === 0 ? (
No messages
- ) : messages.map((message) => ( - - ))} + ) : rootMessages.map((message) => { + const thread = threads.find((t) => t.rootMessageId === message.id) ?? null; + const replyCount = thread ? messages.filter((m) => m.threadId === thread.id).length : 0; + return ( + setSelectedThreadId(thread.id) : null} + /> + ); + })}
-
+