feat: wire order and chat state flow
This commit is contained in:
@@ -8,14 +8,15 @@ import { Badge } from "@/components/ui/badge"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { mockChatMessages, mockChatSessions } from "@/lib/mock"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { useAuthStore } from "@/store/auth"
|
||||
import { useChatStore } from "@/store/chat"
|
||||
|
||||
export default function ChatDetailPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = use(params)
|
||||
const session = mockChatSessions.find((s) => s.id === id)
|
||||
const messages = mockChatMessages.filter((m) => m.sessionId === id)
|
||||
const session = useChatStore((state) => state.sessions.find((item) => item.id === id))
|
||||
const messages = useChatStore((state) => state.messages.filter((item) => item.sessionId === id))
|
||||
const sendTextMessage = useChatStore((state) => state.sendTextMessage)
|
||||
const [input, setInput] = useState("")
|
||||
const { user } = useAuthStore()
|
||||
|
||||
@@ -103,6 +104,21 @@ export default function ChatDetailPage({ params }: { params: Promise<{ id: strin
|
||||
className="flex gap-2 max-w-2xl mx-auto"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
const text = input.trim()
|
||||
if (!text) return
|
||||
|
||||
const sender = session.participants.find(
|
||||
(participant) => participant.id === currentUserId,
|
||||
)
|
||||
sendTextMessage(
|
||||
session.id,
|
||||
{
|
||||
id: currentUserId,
|
||||
name: sender?.name ?? user?.nickname ?? "",
|
||||
avatar: sender?.avatar ?? user?.avatar ?? "",
|
||||
},
|
||||
text,
|
||||
)
|
||||
setInput("")
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user