Files
orca/mobile/src/components/NewWorkspaceSetupScriptField.tsx
T
Neil aa4c9c707c Refactor mobile home, worktree modal, and RPC client (#16165)
* refactor(mobile): split home modal and rpc client

* fix(mobile): restore render-phase remount key in NewWorktreeModal

The split moved the form-reset epoch from render-phase refs into
useState + useLayoutEffect, which changed when the remount key is
computed. On the render where visible flips false->true the key was
still the old epoch, so the previous session's NewWorktreeModalContent
rendered with visible === true carrying stale form state. Child layout
effects run before the parent's, so visible-gated hooks
(useNewWorkspaceRepositories, useNewWorktreeDrawerNavigation,
useNewWorkspaceRuntimeContext) fired for that stale instance before the
parent bumped the epoch and remounted.

Restore the ref-based computation so the key is correct on the first
render where visible flips true, keeping the composite open/client
epoch semantics and the file split intact.
2026-08-24 23:50:10 -07:00

77 lines
2.5 KiB
TypeScript

import { Pressable, Switch, Text, View } from 'react-native'
import type { WorkspaceCreateSetupDecision } from '../tasks/workspace-create-params'
import { colors } from '../theme/mobile-theme'
import { newWorktreeFormStyles as styles } from './new-worktree-form-styles'
import type { SetupRunPolicy } from './new-worktree-modal-types'
export function NewWorkspaceSetupScriptField({
command,
source,
runPolicy,
decision,
runSetup,
onDecisionChange,
onRunSetupChange
}: {
command: string
source: string | null
runPolicy: SetupRunPolicy
decision: Exclude<WorkspaceCreateSetupDecision, 'inherit'> | null
runSetup: boolean
onDecisionChange: (decision: Exclude<WorkspaceCreateSetupDecision, 'inherit'>) => void
onRunSetupChange: (run: boolean) => void
}) {
return (
<View style={styles.field}>
<View style={styles.setupHeader}>
<Text style={styles.label}>Setup script</Text>
{source ? (
<View style={styles.sourceBadge}>
<Text style={styles.sourceBadgeText}>
{source === 'orca.yaml' ? 'ORCA.YAML' : 'HOOKS'}
</Text>
</View>
) : null}
</View>
<View style={styles.setupBox}>
{runPolicy === 'ask' ? (
<View style={styles.setupChoiceRow}>
<Pressable
style={[
styles.setupChoiceButton,
decision === 'run' && styles.setupChoiceButtonSelected
]}
onPress={() => onDecisionChange('run')}
>
<Text style={styles.setupChoiceText}>Run</Text>
</Pressable>
<Pressable
style={[
styles.setupChoiceButton,
decision === 'skip' && styles.setupChoiceButtonSelected
]}
onPress={() => onDecisionChange('skip')}
>
<Text style={styles.setupChoiceText}>Skip</Text>
</Pressable>
</View>
) : (
<View style={styles.setupToggleRow}>
<Text style={styles.setupToggleLabel}>Run setup command</Text>
<Switch
value={runSetup}
onValueChange={onRunSetupChange}
trackColor={{ false: colors.borderSubtle, true: colors.textSecondary }}
thumbColor={colors.textPrimary}
style={styles.setupSwitch}
/>
</View>
)}
<View style={styles.setupCommandBlock}>
<Text style={styles.setupCommand}>{command}</Text>
</View>
</View>
</View>
)
}