From 3b08f94ccc67eb7ea6189d1d12a27d59919d5543 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 10 Aug 2026 20:31:07 +0200 Subject: [PATCH] fix(web): restore the branch's slim chat header The round-3 reconciliation took main's ChatHeader wholesale and wired its full prop set, resurrecting the scripts/open-in/git-actions cluster the branch had deliberately relocated into the thread panel. Restore the 79-line slim header (project favicon + name + thread title) and its minimal ChatView call. #5592's header actions stay a documented v2 follow-up, as decided in round 2. Co-Authored-By: Claude Fable 5 --- apps/web/src/components/ChatView.tsx | 20 -- apps/web/src/components/chat/ChatHeader.tsx | 336 +++----------------- 2 files changed, 37 insertions(+), 319 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 28b3dbe2b9..695adb0674 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -6338,32 +6338,12 @@ function ChatViewContent(props: ChatViewProps) { ? panelLayoutControls : null} diff --git a/apps/web/src/components/chat/ChatHeader.tsx b/apps/web/src/components/chat/ChatHeader.tsx index db13419962..ebff676070 100644 --- a/apps/web/src/components/chat/ChatHeader.tsx +++ b/apps/web/src/components/chat/ChatHeader.tsx @@ -1,340 +1,78 @@ -import { - type EnvironmentId, - type EditorId, - type ProjectScript, - type ResolvedKeybindingsConfig, - type ThreadId, -} from "@t3tools/contracts"; -import { scopeThreadRef } from "@t3tools/client-runtime/environment"; -import { - isAtomCommandInterrupted, - squashAtomCommandFailure, -} from "@t3tools/client-runtime/state/runtime"; -import type { ChangeRequestStateLike } from "@t3tools/client-runtime/state/thread-settled"; -import { ChevronDownIcon } from "lucide-react"; -import { - memo, - useCallback, - useMemo, - useRef, - useState, - type KeyboardEvent as ReactKeyboardEvent, - type MouseEvent as ReactMouseEvent, -} from "react"; -import GitActionsControl from "../GitActionsControl"; -import { type DraftId } from "~/composerDraftStore"; -import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; -import { toastManager } from "../ui/toast"; -import ProjectScriptsControl, { - type NewProjectScriptInput, - type ProjectScriptActionResult, -} from "../ProjectScriptsControl"; -import { OpenInPicker } from "./OpenInPicker"; -import { usePrimaryEnvironmentId } from "../../state/environments"; -import { useT3ProjectFileScripts } from "~/hooks/useT3ProjectFileScripts"; -import { useThreadActionMenu } from "~/hooks/useThreadActionMenu"; -import { threadEnvironment } from "../../state/threads"; -import { useAtomCommand } from "../../state/use-atom-command"; -import { ProjectFavicon } from "../ProjectFavicon"; -import { - WorkspaceBreadcrumb, - WorkspaceBreadcrumbItem, - WorkspaceBreadcrumbSeparator, -} from "../WorkspaceBreadcrumb"; +import { type EnvironmentId } from "@t3tools/contracts"; +import { memo } from "react"; + import { cn } from "~/lib/utils"; +import { ProjectFavicon } from "../ProjectFavicon"; +import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; interface ChatHeaderProps { activeThreadEnvironmentId: EnvironmentId; - activeThreadId: ThreadId; - draftId?: DraftId; activeThreadTitle: string; - /** Drafts have no server thread yet, so the title carries no action menu. */ - isServerThread: boolean; - /** PR state feeding the settled classification, resolved by ChatView. */ - changeRequestState: ChangeRequestStateLike | null; activeProjectName: string | undefined; activeProjectCwd: string | null; - activeProjectFaviconPath: string | null; - openInCwd: string | null; - activeProjectScripts: ReadonlyArray | undefined; - preferredScriptId: string | null; - keybindings: ResolvedKeybindingsConfig; - availableEditors: ReadonlyArray; rightPanelOpen: boolean; - gitCwd: string | null; - readonly onOpenPullRequest?: ((number: number) => void) | undefined; onNewThreadInProject: () => void; - onRunProjectScript: (script: ProjectScript) => void; - onAddProjectScript: (input: NewProjectScriptInput) => Promise; - onUpdateProjectScript: ( - scriptId: string, - input: NewProjectScriptInput, - ) => Promise; - onDeleteProjectScript: (scriptId: string) => Promise; -} - -/** - * Rename commit rule shared with the sidebar's inline rename: trim, reject - * empty (the caller toasts), and skip the mutation when nothing changed. - */ -export function resolveRenameCommit(input: { - readonly title: string; - readonly originalTitle: string; -}): { action: "commit"; title: string } | { action: "reject-empty" } | { action: "noop" } { - const trimmed = input.title.trim(); - if (trimmed.length === 0) return { action: "reject-empty" }; - if (trimmed === input.originalTitle) return { action: "noop" }; - return { action: "commit", title: trimmed }; -} - -export function shouldShowOpenInPicker(input: { - readonly activeProjectName: string | undefined; - readonly activeThreadEnvironmentId: EnvironmentId; - readonly primaryEnvironmentId: EnvironmentId | null; -}): boolean { - return ( - Boolean(input.activeProjectName) && - input.primaryEnvironmentId !== null && - input.activeThreadEnvironmentId === input.primaryEnvironmentId - ); } export const ChatHeader = memo(function ChatHeader({ activeThreadEnvironmentId, - activeThreadId, - draftId, activeThreadTitle, - isServerThread, - changeRequestState, activeProjectName, activeProjectCwd, - activeProjectFaviconPath, - openInCwd, - activeProjectScripts, - preferredScriptId, - keybindings, - availableEditors, rightPanelOpen, - gitCwd, - onOpenPullRequest, onNewThreadInProject, - onRunProjectScript, - onAddProjectScript, - onUpdateProjectScript, - onDeleteProjectScript, }: ChatHeaderProps) { - const primaryEnvironmentId = usePrimaryEnvironmentId(); - const fileScripts = useT3ProjectFileScripts( - activeThreadEnvironmentId, - activeProjectScripts ? activeProjectCwd : null, - ); - const showOpenInPicker = shouldShowOpenInPicker({ - activeProjectName, - activeThreadEnvironmentId, - primaryEnvironmentId, - }); - const activeThreadRef = useMemo( - () => scopeThreadRef(activeThreadEnvironmentId, activeThreadId), - [activeThreadEnvironmentId, activeThreadId], - ); - const updateThreadMetadata = useAtomCommand(threadEnvironment.updateMetadata, { - reportFailure: false, - }); - // Inline rename, keyed by thread: navigating away drops an in-progress - // rename instead of committing stale text. Cleared on thread change (not - // just hidden) so returning to the thread doesn't revive the old draft. - const [renaming, setRenaming] = useState<{ threadId: ThreadId; title: string } | null>(null); - if (renaming !== null && renaming.threadId !== activeThreadId) { - setRenaming(null); - } - const renamingTitle = renaming?.threadId === activeThreadId ? renaming.title : null; - const renameCommittedRef = useRef(false); - const startRename = useCallback(() => { - renameCommittedRef.current = false; - setRenaming({ threadId: activeThreadId, title: activeThreadTitle }); - }, [activeThreadId, activeThreadTitle]); - const commitRename = useCallback( - (title: string) => { - setRenaming(null); - const resolution = resolveRenameCommit({ title, originalTitle: activeThreadTitle }); - if (resolution.action === "reject-empty") { - toastManager.add({ type: "warning", title: "Thread title cannot be empty" }); - return; - } - if (resolution.action === "noop") return; - void updateThreadMetadata({ - environmentId: activeThreadEnvironmentId, - input: { threadId: activeThreadId, title: resolution.title }, - }).then((result) => { - if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) { - const error = squashAtomCommandFailure(result); - toastManager.add({ - type: "error", - title: "Failed to rename thread", - description: error instanceof Error ? error.message : "An error occurred.", - }); - } - }); - }, - [activeThreadEnvironmentId, activeThreadId, activeThreadTitle, updateThreadMetadata], - ); - const { openMenu } = useThreadActionMenu({ - threadRef: isServerThread ? activeThreadRef : null, - projectCwd: activeProjectCwd, - changeRequestState, - onStartRename: startRename, - }); - const titleButtonRef = useRef(null); - const openMenuFromTitle = useCallback(() => { - const rect = titleButtonRef.current?.getBoundingClientRect(); - if (!rect) return; - openMenu({ x: rect.left, y: rect.bottom + 4 }); - }, [openMenu]); - const handleHeaderContextMenu = useCallback( - (event: ReactMouseEvent) => { - if (!isServerThread || renamingTitle !== null) return; - // The right-side controls (git, scripts, open-in) keep their own - // behavior; only the breadcrumb area opens the thread menu. - if ((event.target as HTMLElement).closest("[data-chat-header-actions]")) return; - event.preventDefault(); - openMenu({ x: event.clientX, y: event.clientY }); - }, - [isServerThread, openMenu, renamingTitle], - ); - const handleRenameKeyDown = useCallback( - (event: ReactKeyboardEvent) => { - if (event.key === "Enter") { - renameCommittedRef.current = true; - commitRename(event.currentTarget.value); - } else if (event.key === "Escape") { - renameCommittedRef.current = true; - setRenaming(null); - } - }, - [commitRename], - ); return (
- +
{/* The project always leads the header: knowing which project a thread lives in is priority zero, and the thread title alone doesn't answer it. */} {activeProjectName ? ( - <> - - - - } - > - - {activeProjectName} - - New thread in {activeProjectName} - - - - - ) : null} - - {renamingTitle !== null ? ( - { - if (renameCommittedRef.current) return; - commitRename(event.currentTarget.value); - }} - onFocus={(event) => event.currentTarget.select()} - onKeyDown={handleRenameKeyDown} - /> - ) : isServerThread ? ( + } > -

{activeThreadTitle}

- + {activeProjectName}
- {activeThreadTitle} + New thread in {activeProjectName}
- ) : ( - - - {activeThreadTitle} - - } - /> - {activeThreadTitle} - - )} -
- -
- {activeProjectScripts && ( - + / + + + ) : null} + + + {activeThreadTitle} + + } /> - )} - {showOpenInPicker && ( - - )} - {activeProjectName && ( - - )} + {activeThreadTitle} +
);