@@ -1208,6 +1208,92 @@ function compactionLabel(label: string, title: string | undefined) {
12081208 : label ;
12091209}
12101210
1211+ function RunFoldButton ( {
1212+ entry,
1213+ environmentId,
1214+ threadId,
1215+ onToggle,
1216+ rowSizing,
1217+ iconColor,
1218+ } : {
1219+ entry : Extract < ThreadFeedEntry , { type : "run-fold" } > ;
1220+ environmentId : EnvironmentId ;
1221+ threadId : ThreadId ;
1222+ onToggle : ( runId : RunId ) => void ;
1223+ rowSizing : ReturnType < typeof deriveThreadWorkLogSizing > ;
1224+ iconColor : ColorValue ;
1225+ } ) {
1226+ const loadWork = useAtomCommand ( threadEnvironment . loadEarlierHistory , { reportFailure : false } ) ;
1227+ const anchorsKey = entry . deferredWorkItemIds ?. join ( "\n" ) ?? "" ;
1228+ const [ failed , setFailed ] = useState ( false ) ;
1229+ const load = ( ) => {
1230+ if ( ! anchorsKey ) return ;
1231+ void Promise . all (
1232+ anchorsKey
1233+ . split ( "\n" )
1234+ . map ( ( workAnchorId ) => loadWork ( { environmentId, input : { threadId, workAnchorId } } ) ) ,
1235+ ) . then ( ( results ) =>
1236+ setFailed (
1237+ results . some ( ( result ) => result . _tag === "Failure" || result . value . _tag === "error" ) ,
1238+ ) ,
1239+ ) ;
1240+ } ;
1241+ const loadOnExpand = useEffectEvent ( load ) ;
1242+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Restored expanded folds load their deferred server history on mount.
1243+ useEffect ( ( ) => {
1244+ if ( entry . expanded && anchorsKey && environmentId && threadId ) loadOnExpand ( ) ;
1245+ } , [ entry . expanded , anchorsKey , environmentId , threadId ] ) ;
1246+ const error = anchorsKey && failed ? "Couldn't load work. Tap to retry." : null ;
1247+ const loading = entry . expanded && anchorsKey !== "" && ! failed ;
1248+ const toggle = ( ) => {
1249+ setFailed ( false ) ;
1250+ if ( error && entry . expanded ) load ( ) ;
1251+ else onToggle ( entry . runId ) ;
1252+ } ;
1253+
1254+ return (
1255+ < View className = "min-w-0 flex-1" >
1256+ < Pressable
1257+ accessibilityRole = "button"
1258+ accessibilityState = { { expanded : entry . expanded , busy : loading } }
1259+ onPress = { toggle }
1260+ hitSlop = { 4 }
1261+ className = "min-h-11 min-w-0 flex-1 flex-row items-center gap-2"
1262+ style = { { minHeight : Math . max ( TURN_FOLD_HEIGHT - 3.5 , rowSizing . estimatedRowHeight ) } }
1263+ >
1264+ < Text
1265+ key = { rowSizing . textSizeKey }
1266+ numberOfLines = { 1 }
1267+ className = "shrink font-t3-medium text-sm tabular-nums text-foreground-muted"
1268+ >
1269+ { entry . label }
1270+ { error ? ` · ${ error } ` : "" }
1271+ </ Text >
1272+ < ThreadDisclosureChevron
1273+ expanded = { entry . expanded }
1274+ collapsedDirection = "right"
1275+ size = { 15 }
1276+ tintColor = { iconColor }
1277+ />
1278+ </ Pressable >
1279+ { loading ? (
1280+ < View
1281+ accessible = { false }
1282+ importantForAccessibility = "no-hide-descendants"
1283+ className = "gap-2 px-1 pb-2"
1284+ >
1285+ { ( [ "40%" , "60%" , "33%" ] as const ) . map ( ( width ) => (
1286+ < View key = { width } className = "flex-row items-center gap-2" >
1287+ < View className = "size-3 rounded bg-subtle-strong" />
1288+ < View className = "h-2.5 rounded-full bg-subtle-strong" style = { { width } } />
1289+ </ View >
1290+ ) ) }
1291+ </ View >
1292+ ) : null }
1293+ </ View >
1294+ ) ;
1295+ }
1296+
12111297function renderFeedEntry (
12121298 info : { item : ThreadFeedRow ; index : number } ,
12131299 props : Pick <
@@ -1279,30 +1365,15 @@ function renderFeedEntry(
12791365 if ( entry . type === "run-fold" ) {
12801366 return (
12811367 < View className = "mb-1 flex-row items-center border-b border-border-subtle px-2" >
1282- < Pressable
1283- accessibilityRole = "button"
1284- accessibilityState = { { expanded : entry . expanded } }
1285- onPress = { ( ) => props . onToggleTurnFold ( entry . runId ) }
1286- hitSlop = { 4 }
1287- className = "min-h-11 min-w-0 flex-1 flex-row items-center gap-2"
1288- style = { {
1289- minHeight : Math . max ( TURN_FOLD_HEIGHT - 3.5 , props . workRowSizing . estimatedRowHeight ) ,
1290- } }
1291- >
1292- < Text
1293- key = { props . workRowSizing . textSizeKey }
1294- numberOfLines = { 1 }
1295- className = "shrink font-t3-medium text-sm tabular-nums text-foreground-muted"
1296- >
1297- { entry . label }
1298- </ Text >
1299- < ThreadDisclosureChevron
1300- expanded = { entry . expanded }
1301- collapsedDirection = "right"
1302- size = { 15 }
1303- tintColor = { iconSubtleColor }
1304- />
1305- </ Pressable >
1368+ < RunFoldButton
1369+ key = { entry . id }
1370+ entry = { entry }
1371+ environmentId = { props . environmentId }
1372+ threadId = { props . threadId }
1373+ onToggle = { props . onToggleTurnFold }
1374+ rowSizing = { props . workRowSizing }
1375+ iconColor = { iconSubtleColor }
1376+ />
13061377 { entry . checkpointSummary ? (
13071378 < TurnDiffStat
13081379 checkpoint = { entry . checkpointSummary }
0 commit comments