import { useEffect, useRef } from "react" import { useDictionary } from "@/hooks/use-dictionary" import { cn } from "@/lib/utils" import { useUiStore } from "@/stores/ui-store" import { useVersionsStore } from "@/stores/versions-store" import { useChatEngine } from "./chat-engine" /** Row of version thumbnails under the panel header; click to compare */ export function VersionStrip() { const dict = useDictionary() const versions = useVersionsStore((s) => s.versions) const onCanvasVersionId = useVersionsStore((s) => s.onCanvasVersionId) const openCompare = useUiStore((s) => s.openCompare) const engine = useChatEngine() const scrollRef = useRef(null) // Keep the newest version in view useEffect(() => { const el = scrollRef.current if (el) el.scrollTo({ left: el.scrollWidth, behavior: "smooth" }) }, [versions.length]) // Versions with no card in the chat: saved by older app versions, from // a turn that was retried, or drawn by a call that then failed its // screenshot check (a call still running gets its card when done) const hasCardless = versions.some( (v) => !v.toolCallId || !engine.messages.some((m) => m.parts?.some((p) => { const part = p as { toolCallId?: string; state?: string } return ( part.toolCallId === v.toolCallId && part.state !== "output-error" ) }), ), ) // One version with a card: the strip adds nothing to it if (versions.length < 2 && !hasCardless) return null return (
{dict.versions.strip}
{versions.map((version) => { const isCurrent = version.id === onCanvasVersionId return ( ) })}
) }