diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 22fa9f17c0..6d9c15ab99 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -131,9 +131,9 @@ import { resolveThreadPanelPresentation, } from "../rightPanelLayout"; import { - pullRequestSurfaceId, selectActiveRightPanel, selectActiveRightPanelSurface, + updatePullRequestTabStatus, selectThreadPanelOpen, selectThreadRightPanelState, type RightPanelSurface, @@ -153,6 +153,7 @@ import { selectThreadPreviewMiniPlayer, usePreviewMiniPlayerStore, } from "../previewMiniPlayerStore"; +import { isThreadOwnPullRequest } from "./pullRequest/pullRequestDetail.logic"; import { PullRequestDetailPanel } from "./pullRequest/PullRequestDetailPanel"; import { PullRequestDetailGhost } from "./pullRequest/PullRequestGhosts"; import { PullRequestsUnavailableState } from "./pullRequest/PullRequestsUnavailableState"; @@ -1671,14 +1672,16 @@ function ChatViewContent(props: ChatViewProps) { const [pullRequestTabStatuses, setPullRequestTabStatuses] = useState< Record >({}); - const handlePullRequestTabStatusChange = useCallback((status: PullRequestTabStatus) => { - const id = pullRequestSurfaceId(status); - setPullRequestTabStatuses((current) => - current[id]?.state === status.state && current[id]?.isDraft === status.isDraft - ? current - : { ...current, [id]: status }, - ); - }, []); + const activePullRequestSurfaceId = + activeRightPanelSurface?.kind === "pull-request" ? activeRightPanelSurface.id : undefined; + const handlePullRequestTabStatusChange = useCallback( + (status: PullRequestTabStatus) => { + const id = activePullRequestSurfaceId; + if (id === undefined) return; + setPullRequestTabStatuses((current) => updatePullRequestTabStatus(current, id, status)); + }, + [activePullRequestSurfaceId], + ); const activeFileSurface = activeRightPanelSurface?.kind === "file" ? activeRightPanelSurface : null; const activePreviewState = useThreadPreviewState(activeThreadRef); @@ -6149,11 +6152,23 @@ function ChatViewContent(props: ChatViewProps) { number: activeRightPanelSurface.number, }} context={ - activeThreadPr?.number === activeRightPanelSurface.number && - threadRepository === activeRightPanelSurface.repository + isThreadOwnPullRequest( + { + projectId: activeProject?.id ?? null, + repository: threadRepository, + number: activeThreadPr?.number ?? null, + }, + { + projectId: activeRightPanelSurface.projectId, + repository: activeRightPanelSurface.repository, + number: activeRightPanelSurface.number, + }, + ) ? "thread" : "page" } + chromeVariant="collapse" + composerDraftTarget={composerDraftTarget} onStateChange={handlePullRequestTabStatusChange} /> ) : activeRightPanelSurface?.kind === "agents" ? (