@@ -5,14 +5,15 @@ import {
55} from "@t3tools/contracts" ;
66import { worktreeSetupAgentStarted } from "@t3tools/client-runtime/worktree-setup" ;
77import { formatDuration } from "@t3tools/shared/orchestrationTiming" ;
8- import { useEffect , useState } from "react" ;
9- import { AppState , Platform , Pressable , ScrollView , View } from "react-native" ;
8+ import { useState } from "react" ;
9+ import { Platform , Pressable , ScrollView , View } from "react-native" ;
1010import { useSafeAreaInsets } from "react-native-safe-area-context" ;
1111import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator" ;
1212import { AppText as Text } from "../../components/ui/AppText" ;
1313import { SymbolView , type AppSymbolName } from "../../components/ui/AppSymbol" ;
1414import { WorktreeSetupSheet } from "./worktree-setup-sheet" ;
1515import { ShimmeringWorkContent } from "./thread-work-log" ;
16+ import { useVisibleSecondClock } from "./use-visible-second-clock" ;
1617
1718export interface WorktreeSetupCardProps {
1819 snapshot : WorktreeSetupSnapshot ;
@@ -45,7 +46,7 @@ export function WorktreeSetupCard(props: WorktreeSetupCardProps) {
4546 const backgroundSetup = handedOff && running ;
4647 const scriptName = snapshot . setupScript ?. name ?? "Setup script" ;
4748 const [ detailsOpen , setDetailsOpen ] = useState ( false ) ;
48- const now = useSetupClock ( running || working ) ;
49+ const now = useVisibleSecondClock ( running || working ) ;
4950 const failed =
5051 snapshot . phase === "failed" || snapshot . stages . some ( ( stage ) => stage . status === "failed" ) ;
5152 const label =
@@ -147,7 +148,7 @@ export function WorktreeSetupCard(props: WorktreeSetupCardProps) {
147148}
148149
149150export function WorktreeWorkingHeader ( { startedAt } : { startedAt : string } ) {
150- const now = useSetupClock ( true ) ;
151+ const now = useVisibleSecondClock ( true ) ;
151152 return (
152153 < View className = "py-1" >
153154 < View className = "min-h-11 flex-row items-center border-b border-border px-1" >
@@ -188,21 +189,6 @@ function HeaderLabel({
188189 ) ;
189190}
190191
191- function useSetupClock ( active : boolean ) {
192- const [ now , setNow ] = useState ( Date . now ) ;
193- const [ appState , setAppState ] = useState ( AppState . currentState ) ;
194- useEffect ( ( ) => {
195- const subscription = AppState . addEventListener ( "change" , setAppState ) ;
196- return ( ) => subscription . remove ( ) ;
197- } , [ ] ) ;
198- useEffect ( ( ) => {
199- if ( ! active || appState !== "active" ) return ;
200- const timer = setInterval ( ( ) => setNow ( Date . now ( ) ) , 1000 ) ;
201- return ( ) => clearInterval ( timer ) ;
202- } , [ active , appState ] ) ;
203- return now ;
204- }
205-
206192function SetupDetailsSheet ( {
207193 snapshot,
208194 turnStarted,
0 commit comments