({ onDone }: Props)
| 24 | }; |
| 25 | |
| 26 | export function BridgeDialog({ onDone }: Props): React.ReactNode { |
| 27 | useRegisterOverlay('bridge-dialog'); |
| 28 | |
| 29 | const connected = useAppState(s => s.replBridgeConnected); |
| 30 | const sessionActive = useAppState(s => s.replBridgeSessionActive); |
| 31 | const reconnecting = useAppState(s => s.replBridgeReconnecting); |
| 32 | const connectUrl = useAppState(s => s.replBridgeConnectUrl); |
| 33 | const sessionUrl = useAppState(s => s.replBridgeSessionUrl); |
| 34 | const error = useAppState(s => s.replBridgeError); |
| 35 | const explicit = useAppState(s => s.replBridgeExplicit); |
| 36 | const environmentId = useAppState(s => s.replBridgeEnvironmentId); |
| 37 | const sessionId = useAppState(s => s.replBridgeSessionId); |
| 38 | const verbose = useAppState(s => s.verbose); |
| 39 | const setAppState = useSetAppState(); |
| 40 | |
| 41 | const [showQR, setShowQR] = useState(false); |
| 42 | const [qrText, setQrText] = useState(''); |
| 43 | const [branchName, setBranchName] = useState(''); |
| 44 | |
| 45 | const repoName = basename(getOriginalCwd()); |
| 46 | |
| 47 | // Fetch branch name on mount |
| 48 | useEffect(() => { |
| 49 | getBranch() |
| 50 | .then(setBranchName) |
| 51 | .catch(() => {}); |
| 52 | }, []); |
| 53 | |
| 54 | // The URL to display/QR: session URL when connected, connect URL when ready |
| 55 | const displayUrl = sessionActive ? sessionUrl : connectUrl; |
| 56 | |
| 57 | // Generate QR code when URL changes or QR is toggled on |
| 58 | useEffect(() => { |
| 59 | if (!showQR || !displayUrl) { |
| 60 | setQrText(''); |
| 61 | return; |
| 62 | } |
| 63 | qrToString(displayUrl, { |
| 64 | type: 'terminal', |
| 65 | errorCorrectionLevel: 'L', |
| 66 | small: true, |
| 67 | }) |
| 68 | .then(setQrText) |
| 69 | .catch(() => setQrText('')); |
| 70 | }, [showQR, displayUrl]); |
| 71 | |
| 72 | useKeybindings( |
| 73 | { |
| 74 | 'confirm:yes': onDone, |
| 75 | 'confirm:toggle': () => { |
| 76 | setShowQR(prev => !prev); |
| 77 | }, |
| 78 | }, |
| 79 | { context: 'Confirmation' }, |
| 80 | ); |
| 81 | |
| 82 | useInput(input => { |
| 83 | if (input === 'd') { |
nothing calls this directly
no test coverage detected