Files
orca/mobile/src/components/NewWorktreeModalController.tsx
T
c9bd61376f feat(mobile): combine PR sidebar and checks parity (#5641)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Orca <help@stably.ai>
Co-authored-by: gsxdsm <gsxdsm@users.noreply.github.com>
2026-06-17 22:52:12 -07:00

67 lines
1.6 KiB
TypeScript

import { forwardRef, useCallback, useEffect, useImperativeHandle, useState } from 'react'
import type { RpcClient } from '../transport/rpc-client'
import { NewWorktreeModal } from './NewWorktreeModal'
export type NewWorktreeModalControllerHandle = {
open: () => void
}
type Props = {
routeVisible: boolean
client: RpcClient | null
hostId?: string
existingWorktreePaths?: readonly string[]
onVisibleChange?: (visible: boolean) => void
onRouteVisibleChange: (visible: boolean) => void
onCreated: (worktreeId: string, name: string) => void
}
export const NewWorktreeModalController = forwardRef<NewWorktreeModalControllerHandle, Props>(
function NewWorktreeModalController(
{
routeVisible,
client,
hostId,
existingWorktreePaths,
onVisibleChange,
onRouteVisibleChange,
onCreated
},
ref
) {
const [manualVisible, setManualVisible] = useState(false)
const visible = routeVisible || manualVisible
useImperativeHandle(
ref,
() => ({
open: () => setManualVisible(true)
}),
[]
)
const close = useCallback(() => {
setManualVisible(false)
if (routeVisible) {
onRouteVisibleChange(false)
}
}, [onRouteVisibleChange, routeVisible])
useEffect(() => {
onVisibleChange?.(visible)
}, [onVisibleChange, visible])
return (
<NewWorktreeModal
visible={visible}
client={client}
hostId={hostId}
existingWorktreePaths={existingWorktreePaths}
onCreated={onCreated}
onClose={close}
/>
)
}
)