import { useEffect } from "react"; import { useT } from "../i18n"; import { flushOutbox, removeFromOutbox, useOutbox } from "../outbox"; import { useStore } from "../store"; import { Icon } from "./Icon"; /** Messages waiting for a connection: sent automatically once the server is reachable again. */ export function OutboxBar({ sessionId }: { sessionId: string }) { const t = useT(); const items = useOutbox(sessionId); const connected = useStore((s) => s.connected); useEffect(() => { if (!items.length) return; const go = () => void flushOutbox(sessionId); if (connected && navigator.onLine) go(); window.addEventListener("online", go); return () => window.removeEventListener("online", go); }, [sessionId, connected, items.length]); if (!items.length) return null; return (
{t("outbox.waiting", { n: items.length })}
{items.map((i) => (
{i.text.length > 120 ? `${i.text.slice(0, 120)}…` : i.text}
))}
); }