import { CircleAlert } from "lucide-react"; import { useLayoutEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { MarkdownText, preloadMarkdownText } from "@/components/MarkdownText"; import { Button } from "@/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { useToast } from "@/components/ui/toast"; import { useOverlayEscapeFocus } from "@/hooks/useOverlayEscapeFocus"; import type { GoalStateWsPayload } from "@/lib/types"; import "./goal-island.css"; export function GoalIsland({ goal, cancelDisabled, onCancel }: { goal: GoalStateWsPayload; cancelDisabled: boolean; onCancel: () => Promise; }) { const { t } = useTranslation(); const [open, setOpen] = useState(false); const [cancelling, setCancelling] = useState(false); const showToast = useToast(); const [scrollBody, setScrollBody] = useState(null); const panelRef = useRef(null); const escapeFocus = useOverlayEscapeFocus(); const changeOpen = (nextOpen: boolean) => { const panel = panelRef.current; const surface = panel?.querySelector(":scope > .goal-island-surface"); const content = panel?.querySelector(".goal-island-panel-content"); if (panel && surface && content) { const shape = getComputedStyle(surface); const text = getComputedStyle(content); panel.style.setProperty("--goal-from-width", shape.width); panel.style.setProperty("--goal-from-height", shape.height); panel.style.setProperty("--goal-from-radius", shape.getPropertyValue("--goal-island-radius")); panel.style.setProperty("--goal-from-opacity", text.opacity); panel.style.setProperty("--goal-from-transform", text.transform); } setOpen(nextOpen); }; const summary = goal.ui_summary?.trim() ?? ""; const objective = goal.objective?.trim() ?? ""; const label = summary || objective || t("thread.composer.goalStateFallback"); const status = goal.status === "blocked" ? "blocked" : "active"; const recap = goal.recap?.trim() ?? ""; const collapsedLabel = status === "blocked" ? recap : label; const cancelButton = ; useLayoutEffect(() => { if (!scrollBody) return; if (status === "blocked") scrollBody.scrollTop = 0; const measure = () => { scrollBody.toggleAttribute("data-overflow-top", scrollBody.scrollTop > 1); scrollBody.toggleAttribute("data-overflow-bottom", scrollBody.scrollHeight - scrollBody.clientHeight - scrollBody.scrollTop > 1); }; measure(); const observer = new ResizeObserver(measure); observer.observe(scrollBody); if (scrollBody.firstElementChild) observer.observe(scrollBody.firstElementChild); scrollBody.addEventListener("scroll", measure, { passive: true }); return () => { observer.disconnect(); scrollBody.removeEventListener("scroll", measure); }; }, [scrollBody, status]); return (
{status !== "blocked" ?
{summary ?

{summary}

: null} {cancelButton}
: null}
{status === "blocked" ?
: null} {objective ? {objective} : null} {status !== "blocked" && recap ? {recap} : null}
); }