1- import { useCallback , useEffect , useMemo } from "react" ;
1+ import { useCallback , useEffect , useMemo , useState } from "react" ;
22import * as DateTime from "effect/DateTime" ;
33
44import {
@@ -130,13 +130,19 @@ export function useReviewSections(input: {
130130 const activeSectionId = activeCheckpoint
131131 ? getReviewSectionIdForCheckpoint ( activeCheckpoint )
132132 : null ;
133+ const gitScopeKey = `${ environmentId } :${ threadId } :${ activeSectionId } ` ;
134+ const [ gitVisibility , setGitVisibility ] = useState < { scope : string ; visible : boolean } | null > (
135+ null ,
136+ ) ;
137+ const includeGitChanges = gitVisibility ?. scope === gitScopeKey && gitVisibility . visible ;
133138 const activeTurnDiff = useCheckpointDiff ( {
134139 environmentId : enabled ? ( environmentId ?? null ) : null ,
135140 threadId : enabled ? ( threadId ?? null ) : null ,
136141 fromTurnCount :
137142 enabled && activeCheckpoint ? Math . max ( 0 , activeCheckpoint . checkpointTurnCount - 1 ) : null ,
138143 toTurnCount : enabled ? ( activeCheckpoint ?. checkpointTurnCount ?? null ) : null ,
139144 ignoreWhitespace : false ,
145+ includeGitChanges,
140146 } ) ;
141147
142148 useEffect ( ( ) => {
@@ -150,9 +156,12 @@ export function useReviewSections(input: {
150156 if ( ! reviewCache . threadKey || ! activeSectionId || ! activeTurnDiff . data ) {
151157 return ;
152158 }
153- setReviewTurnDiff ( reviewCache . threadKey , activeSectionId , activeTurnDiff . data . diff ) ;
159+ // This section cache holds only the default view. Full patches stay in the query's keyed cache.
160+ if ( ! includeGitChanges ) {
161+ setReviewTurnDiff ( reviewCache . threadKey , activeSectionId , activeTurnDiff . data . diff ) ;
162+ }
154163 setReviewAsyncError ( reviewCache . threadKey , null ) ;
155- } , [ activeSectionId , activeTurnDiff . data , reviewCache . threadKey ] ) ;
164+ } , [ activeSectionId , activeTurnDiff . data , includeGitChanges , reviewCache . threadKey ] ) ;
156165
157166 useEffect ( ( ) => {
158167 if ( reviewCache . threadKey && activeTurnDiff . error ) {
@@ -181,6 +190,9 @@ export function useReviewSections(input: {
181190 ) ;
182191
183192 return {
193+ gitFileCount : selectedSection ?. kind === "turn" ? ( activeTurnDiff . data ?. gitFileCount ?? 0 ) : 0 ,
194+ includeGitChanges,
195+ toggleGitChanges : ( ) => setGitVisibility ( { scope : gitScopeKey , visible : ! includeGitChanges } ) ,
184196 error : diffPreview . error ?? activeTurnDiff . error ?? reviewCache . asyncState . error ,
185197 isSelectedSectionPending :
186198 selectedSection ?. kind === "turn" ? activeTurnDiff . isPending : diffPreview . isPending ,
@@ -190,7 +202,14 @@ export function useReviewSections(input: {
190202 : undefined ,
191203 loadingTurnIds,
192204 reviewSections,
193- selectedSection,
205+ selectedSection :
206+ selectedSection ?. kind === "turn"
207+ ? {
208+ ...selectedSection ,
209+ diff : activeTurnDiff . data ?. diff ?? ( includeGitChanges ? null : selectedSection . diff ) ,
210+ isLoading : activeTurnDiff . isPending ,
211+ }
212+ : selectedSection ,
194213 refreshSelectedSection,
195214 selectSection,
196215 } ;
0 commit comments