diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.ts index 5f6c234e5f..dee272591c 100644 --- a/apps/web/src/components/Sidebar.logic.test.ts +++ b/apps/web/src/components/Sidebar.logic.test.ts @@ -15,6 +15,7 @@ import { resolveSidebarNewThreadSeedContext, resolveSidebarNewThreadEnvMode, resolveSidebarStageBadgeLabel, + resolveSidebarThreadRowTransientProps, resolveThreadRowClassName, resolveThreadStatusPill, shouldClearThreadSelectionOnMouseDown, @@ -38,6 +39,51 @@ import { const localEnvironmentId = EnvironmentId.make("environment-local"); +describe("resolveSidebarThreadRowTransientProps", () => { + it("only publishes rename state to the row being edited", () => { + expect( + resolveSidebarThreadRowTransientProps({ + threadKey: "thread-1", + renamingThreadKey: "thread-1", + renamingTitle: "Edited title", + confirmingArchiveThreadKey: null, + }), + ).toEqual({ + isRenaming: true, + renamingTitle: "Edited title", + isConfirmingArchive: false, + }); + + expect( + resolveSidebarThreadRowTransientProps({ + threadKey: "thread-2", + renamingThreadKey: "thread-1", + renamingTitle: "Edited title", + confirmingArchiveThreadKey: null, + }), + ).toEqual({ + isRenaming: false, + renamingTitle: "", + isConfirmingArchive: false, + }); + }); + + it("only publishes archive confirmation state to its target row", () => { + expect( + resolveSidebarThreadRowTransientProps({ + threadKey: "thread-2", + renamingThreadKey: null, + renamingTitle: "", + confirmingArchiveThreadKey: "thread-2", + }), + ).toEqual({ + isRenaming: false, + renamingTitle: "", + isConfirmingArchive: true, + }); + }); +}); + describe("resolveSidebarStageBadgeLabel", () => { it("returns Nightly for nightly primary server versions", () => { expect( diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.ts index 91a61cc155..721ae2db34 100644 --- a/apps/web/src/components/Sidebar.logic.ts +++ b/apps/web/src/components/Sidebar.logic.ts @@ -17,6 +17,25 @@ export const THREAD_JUMP_HINT_SHOW_DELAY_MS = 100; // nearby thread usually reuses an already-hot subscription. export const SIDEBAR_THREAD_PREWARM_LIMIT = 10; export type SidebarNewThreadEnvMode = "local" | "worktree"; + +export function resolveSidebarThreadRowTransientProps(input: { + threadKey: string; + renamingThreadKey: string | null; + renamingTitle: string; + confirmingArchiveThreadKey: string | null; +}): { + isRenaming: boolean; + renamingTitle: string; + isConfirmingArchive: boolean; +} { + const isRenaming = input.renamingThreadKey === input.threadKey; + return { + isRenaming, + renamingTitle: isRenaming ? input.renamingTitle : "", + isConfirmingArchive: input.confirmingArchiveThreadKey === input.threadKey, + }; +} + type SidebarProject = { id: string; title: string; diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 6a76494daa..36e7a31f20 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -192,6 +192,7 @@ import { resolveSidebarNewThreadSeedContext, resolveSidebarNewThreadEnvMode, resolveSidebarStageBadgeLabel, + resolveSidebarThreadRowTransientProps, resolveThreadRowClassName, resolveThreadStatusPill, orderItemsByPreferredIds, @@ -324,13 +325,13 @@ interface SidebarThreadRowProps { isActive: boolean; jumpLabel: string | null; appSettingsConfirmThreadArchive: boolean; - renamingThreadKey: string | null; + isRenaming: boolean; renamingTitle: string; setRenamingTitle: (title: string) => void; startThreadRename: (threadKey: string, title: string) => void; renamingInputRef: React.RefObject; renamingCommittedRef: React.RefObject; - confirmingArchiveThreadKey: string | null; + isConfirmingArchive: boolean; setConfirmingArchiveThreadKey: React.Dispatch>; confirmArchiveButtonRefs: React.RefObject>; handleThreadClick: ( @@ -361,13 +362,13 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr isActive, jumpLabel, appSettingsConfirmThreadArchive, - renamingThreadKey, + isRenaming, renamingTitle, setRenamingTitle, startThreadRename, renamingInputRef, renamingCommittedRef, - confirmingArchiveThreadKey, + isConfirmingArchive, setConfirmingArchiveThreadKey, confirmArchiveButtonRefs, handleThreadClick, @@ -468,8 +469,8 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr const pr = resolveThreadPr(thread.branch, gitStatus.data); const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider); const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds); - const isConfirmingArchive = confirmingArchiveThreadKey === threadKey && !isThreadRunning; - const threadMetaClassName = isConfirmingArchive + const showArchiveConfirmation = isConfirmingArchive && !isThreadRunning; + const threadMetaClassName = showArchiveConfirmation ? "pointer-events-none opacity-0" : !isThreadRunning ? "pointer-events-none transition-opacity duration-150 max-sm:pr-6 group-hover/menu-sub-item:opacity-0 group-focus-within/menu-sub-item:opacity-0" @@ -502,7 +503,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr (event: React.MouseEvent) => { // Already renaming this row: a double-click on the row chrome (outside the // input) must not restart and discard the in-progress edit. - if (renamingThreadKey === threadKey) return; + if (isRenaming) return; // On mobile the first tap navigates and closes the sidebar sheet, so the // inline rename can't be shown. Renaming there stays on the context menu. if (isMobile) return; @@ -514,7 +515,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr event.preventDefault(); startThreadRename(threadKey, thread.title); }, - [isMobile, renamingThreadKey, startThreadRename, threadKey, thread.title], + [isMobile, isRenaming, startThreadRename, threadKey, thread.title], ); const handleRowKeyDown = useCallback( (event: React.KeyboardEvent) => { @@ -709,7 +710,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr )} {threadStatus && } - {renamingThreadKey === threadKey ? ( + {isRenaming ? ( - {isConfirmingArchive ? ( + {showArchiveConfirmation ? (