// Grape Elevate — Inbox screen function Inbox({ t, conversations, setConversations }) { const [filter, setFilter] = React.useState('all'); const [activeId, setActiveId] = React.useState(conversations[0]?.id); const [draft, setDraft] = React.useState(''); const scrollRef = React.useRef(null); const list = conversations.filter((c) => { if (filter === 'unread') return c.unread > 0; if (filter === 'bot') return c.bot; if (filter === 'human') return !c.bot; return true; }); const active = conversations.find((c) => c.id === activeId); React.useEffect(() => { if (active && active.unread > 0) { setConversations((cs) => cs.map((c) => c.id === active.id ? { ...c, unread: 0 } : c)); } // scroll to bottom on switch if (scrollRef.current) scrollRef.current.scrollTop = scrollRef.current.scrollHeight; }, [activeId]); const send = () => { const text = draft.trim(); if (!text || !active) return; setConversations((cs) => cs.map((c) => c.id === active.id ? { ...c, msgs: [...c.msgs, { from: 'me', text, t: 'agora' }], last: text, time: 'agora' } : c)); setDraft(''); setTimeout(() => { if (scrollRef.current) scrollRef.current.scrollTop = scrollRef.current.scrollHeight; }, 30); }; return ( <>

{t('inbox.title')}

{t('inbox.subtitle')}

{/* Conversation list */} {/* Thread */}
{active ? ( <>
{active.name}
{active.handle} · {active.source}
{active.msgs.map((m, i) => (
{m.from === 'bot' &&
{t('inbox.bot')}
}
{m.text}
{m.t}
))}