import { useEffect, useRef, useState, type FormEvent, type KeyboardEvent } from "react"; import { useNavigate } from "react-router-dom"; import { AppShell, TopBar } from "../components/AppShell"; import { Icon } from "../components/Icon"; import { VoiceInput } from "../components/VoiceInput"; import { ru } from "../content/ru"; import { useDialog } from "../dialog/DialogContext"; // I1 · Сообщения: вся переписка с помощником; быстрые ответы — кнопки последнего сообщения движка. export function Messages() { const t = ru.messages; const navigate = useNavigate(); const dialog = useDialog(); const [draft, setDraft] = useState(""); const endRef = useRef(null); const quick = dialog.pending.flatMap((r) => r.buttons.flat()); useEffect(() => { dialog.markRead(); endRef.current?.scrollIntoView({ block: "end" }); }, [dialog.entries.length, dialog.live?.text, dialog.live?.status.length]); const send = async (e?: FormEvent) => { e?.preventDefault(); const text = draft.trim(); if (!text || dialog.busy) return; setDraft(""); if (!(await dialog.send({ type: "text", text }, text))) setDraft(text); }; const onKeyDown = (e: KeyboardEvent) => { if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) { e.preventDefault(); void send(); } }; return (
navigate("/today")} title={t.title} /> {dialog.entries.length === 0 &&

{t.empty}

}
    {dialog.entries.map((e) => e.from === "assistant" ? (
  1. {e.reply.text}

  2. ) : (
  3. {t.you}:

    {e.text}

  4. ), )} {dialog.live && (
  5. {dialog.live.status.map((st, i) => (

    {st}

    ))} {dialog.live.text ? (

    {dialog.live.text}

    ) : (

    )}
  6. )}
{quick.length > 0 && (
{quick.map((b) => ( ))}
)}