import { useEffect, useState } from "react"; import { get } from "../api"; import { fmtMsgTime, useT } from "../i18n"; import { Markdown } from "./Markdown"; interface Shared { title: string; messages: { id: string; role: "user" | "assistant"; text: string; created_at: number }[]; } /** A chat opened through a read-only link (no account needed). */ export function PublicChat({ token }: { token: string }) { const t = useT(); const [chat, setChat] = useState(); const [error, setError] = useState(); useEffect(() => { get(`/public/chat/${encodeURIComponent(token)}`) .then((c) => (setChat(c), (document.title = `${c.title || "Chat"} – CodeCraft`))) .catch((e) => setError(e.message)); }, [token]); if (error) return
{error}
; if (!chat) return
{t("common.loading")}
; return (

{chat.title || "Chat"}

{t("link.readOnly")}
{chat.messages.map((m) => (
{fmtMsgTime(m.created_at)}
))}
); }