import { useState } from 'react' import { useApp } from '../context/AppContext' import { colorToCss } from '../utils/color' import { connectionStatus } from '../utils/connection' import MessageList from './MessageList' import MessageInput from './MessageInput' export default function ChatArea() { const { state, userId } = useApp() const conn = state.connections.find(c => c.id === state.selectedId) const [pendingFile, setPendingFile] = useState(null) const [dragCount, setDragCount] = useState(0) const isDragging = dragCount > 0 function onDragEnter(e) { if (Array.from(e.dataTransfer?.types ?? []).includes('Files')) { setDragCount(c => c + 1) } } function onDragLeave() { setDragCount(c => Math.max(0, c - 1)) } function onDragOver(e) { if (Array.from(e.dataTransfer?.types ?? []).includes('Files')) { e.preventDefault() } } function onDrop(e) { e.preventDefault() setDragCount(0) const file = e.dataTransfer?.files?.[0] if (file && state.selectedId) setPendingFile(file) } let header = null if (conn) { const otherId = conn.requestorId === userId ? conn.recipientId : conn.requestorId const other = state.userMap[otherId] const status = connectionStatus(conn, userId) header = (
{other?.name?.[0]?.toUpperCase() ?? '?'}

{other?.name ?? '…'}

{other?.pronouns && (

{other.pronouns}

)}
{status && ( ● {status.label} )}
) } return (
{header} {state.selectedId ? ( <> ) : (
Select a conversation
)} {isDragging && state.selectedId && (

Drop file to attach

)}
) }