diff --git a/apps/android/src/screens/workspace-modals.tsx b/apps/android/src/screens/workspace-modals.tsx new file mode 100644 index 0000000..bfd64b4 --- /dev/null +++ b/apps/android/src/screens/workspace-modals.tsx @@ -0,0 +1,629 @@ +import { useEffect, useRef, useState, type ReactNode } from 'react' +import { + Keyboard, + Modal, + Pressable, + ScrollView, + StyleSheet, + Text, + TextInput, + View, +} from 'react-native' +import { + ArrowDown, + ArrowUp, + Check, + CirclePlus, + Code2, + Eye, + EyeOff, + Folder, + FolderOpen, + Pencil, + Plus, + Sparkles, + Star, + Trash2, + X, + type LucideIcon, +} from 'lucide-react-native' +import { deviceVersionSubtitle, platformIcon } from '../lib/device-display' +import { useAppStore } from '../state/store' +import type { AgentBackend, DirectoryListing, WorkspaceView } from '../types' +import { BlurHeaderFrame, Button, GroupCard, GroupRow, IconButton, Screen, SectionTitle, TopBar } from '../ui/components' +import { radius, spacing, type } from '../ui/theme' +import { useTheme, type ThemeColors } from '../ui/theme-context' +import { useResponsiveLayout } from '../ui/responsive' +import { useThemedStyles } from '../ui/use-themed-styles' +import { SheetModal } from '../ui/sheet' +import { strings } from '../locales/i18n' + +const DIRECTORY_SHEET_COMPACT_RATIO = 0.92 +const DIRECTORY_SHEET_RATIO = 0.75 + +export function WorkspaceActionsModal({ + target, + favorited = false, + canMoveUp, + canMoveDown, + busy, + onClose, + onNewSession, + onToggleFavorite, + onRename, + onMoveUp, + onMoveDown, + onDelete, +}: { + target?: WorkspaceView + favorited?: boolean + canMoveUp: boolean + canMoveDown: boolean + busy: boolean + onClose: () => void + onNewSession?: () => void + onToggleFavorite?: () => void + onRename: () => void + onMoveUp: () => void + onMoveDown: () => void + onDelete: () => void +}) { + const styles = useThemedStyles(createStyles) + const { sheetMaxHeight } = useResponsiveLayout() + const canManage = target !== undefined && (target.backend === undefined || target.backend === 'harness') + + return ( + + + + + {strings.workspaces.options} + {target !== undefined && {target.title}} + + + + + {target !== undefined && Boolean(target.path) && ( + {target.path} + )} + {target !== undefined && ( + + {onNewSession !== undefined && ( + + )} + {onToggleFavorite !== undefined && ( + + )} + {canManage && ( + + )} + {canManage && ( + + )} + {canManage && ( + + )} + + )} + {canManage && ( + + + + )} + + + ) +} + +export function CreateWorkspaceModal({ + visible, + codexAvailable, + cursorAvailable, + antigravityAvailable, + piAvailable, + opencodeAvailable, + claudeAvailable, + hermesAvailable, + initialBackend, + busy, + onClose, + onCreate, + onCreated, +}: { + visible: boolean + codexAvailable: boolean + cursorAvailable: boolean + antigravityAvailable: boolean + piAvailable: boolean + opencodeAvailable: boolean + claudeAvailable: boolean + hermesAvailable: boolean + initialBackend: AgentBackend + busy: boolean + onClose: () => void + onCreate: (path: string, backend: AgentBackend) => Promise + onCreated: (workspace: WorkspaceView) => void +}) { + useAppStore(state => state.language) + const selectedDevice = useAppStore(state => state.selectedDevice) + const connectionPhase = useAppStore(state => state.connection.phase) + const [backend, setBackend] = useState('harness') + const [path, setPath] = useState('') + const [browseOpen, setBrowseOpen] = useState(false) + const { colors } = useTheme() + const styles = useThemedStyles(createStyles) + const { contentMaxWidth, landscape } = useResponsiveLayout() + const sheetScrollRef = useRef(null) + const requestEpochRef = useRef(0) + + useEffect(() => { + requestEpochRef.current += 1 + if (visible) sheetScrollRef.current?.scrollTo({ y: 0, animated: false }) + }, [visible, selectedDevice?.deviceId]) + + useEffect(() => { + if (!visible) return + if (initialBackend === 'codex' && codexAvailable) setBackend('codex') + else if (initialBackend === 'cursor' && cursorAvailable) setBackend('cursor') + else if (initialBackend === 'pi' && piAvailable) setBackend('pi') + else if (initialBackend === 'antigravity' && antigravityAvailable) setBackend('antigravity') + else if (initialBackend === 'opencode' && opencodeAvailable) setBackend('opencode') + else if (initialBackend === 'claude' && claudeAvailable) setBackend('claude') + else if (initialBackend === 'hermes' && hermesAvailable) setBackend('hermes') + else setBackend('harness') + }, [codexAvailable, cursorAvailable, antigravityAvailable, piAvailable, opencodeAvailable, claudeAvailable, hermesAvailable, initialBackend, visible]) + + const dismissModal = () => { + requestEpochRef.current += 1 + setBrowseOpen(false) + onClose() + } + + const create = async () => { + const trimmed = path.trim() + if (trimmed.length === 0) return + const epoch = requestEpochRef.current + const targetDeviceId = selectedDevice?.deviceId + const workspace = await onCreate(trimmed, backend) + if ( + workspace === undefined + || requestEpochRef.current !== epoch + || useAppStore.getState().selectedDevice?.deviceId !== targetDeviceId + ) { + return + } + setPath('') + dismissModal() + onCreated(workspace) + } + + const openBrowser = () => { + Keyboard.dismiss() + setBrowseOpen(true) + } + + const backendItems: Array<{ value: AgentBackend; label: string; detail: string; icon: LucideIcon }> = [ + { value: 'harness', label: strings.workspaces.dsh, detail: strings.devices.harness, icon: FolderOpen }, + ...(codexAvailable ? [{ value: 'codex' as const, label: strings.workspaces.codex, detail: 'OpenAI Codex', icon: Code2 }] : []), + ...(claudeAvailable ? [{ value: 'claude' as const, label: strings.workspaces.claude, detail: 'Anthropic Claude', icon: Sparkles }] : []), + ...(hermesAvailable ? [{ value: 'hermes' as const, label: strings.workspaces.hermes, detail: 'Nous Research Hermes', icon: Sparkles }] : []), + ...(cursorAvailable ? [{ value: 'cursor' as const, label: strings.workspaces.cursor, detail: 'Cursor ACP', icon: Sparkles }] : []), + ...(antigravityAvailable ? [{ value: 'antigravity' as const, label: strings.workspaces.antigravity, detail: 'Antigravity ACP', icon: Sparkles }] : []), + ...(opencodeAvailable ? [{ value: 'opencode' as const, label: strings.workspaces.opencode, detail: 'OpenCode ACP', icon: Sparkles }] : []), + ...(piAvailable ? [{ value: 'pi' as const, label: strings.workspaces.pi, detail: 'Pi ACP', icon: Sparkles }] : []), + ] + + const directoryHint = backend === 'codex' + ? strings.workspaces.codexDirectoryHint + : backend === 'cursor' + ? strings.workspaces.cursorDirectoryHint + : backend === 'pi' + ? strings.workspaces.piDirectoryHint + : backend === 'antigravity' + ? strings.workspaces.antigravityDirectoryHint + : backend === 'opencode' + ? strings.workspaces.opencodeDirectoryHint + : backend === 'claude' + ? strings.workspaces.claudeDirectoryHint + : backend === 'hermes' + ? strings.workspaces.hermesDirectoryHint + : strings.workspaces.directoryHint + + const HostIcon = selectedDevice ? platformIcon(selectedDevice.platform) : FolderOpen + const hostOnline = connectionPhase === 'connected' + const hostConnecting = connectionPhase === 'connecting' || connectionPhase === 'reconnecting' + const hostStatusDot = hostOnline ? colors.success : hostConnecting ? colors.warning : colors.disabled + const hostStatusLabel = hostOnline ? strings.status.online : hostConnecting ? strings.status.waiting : strings.status.offline + + return ( + + + + } + > + + + {selectedDevice !== undefined && ( + <> + {strings.sessionInfo.host} + + + + {hostStatusLabel} + + } + /> + + + )} + + {strings.workspaces.deviceDirectory} + + + + + + + + {path.length > 0 && !busy && ( + setPath('')} + style={({ pressed }) => [styles.clearSearch, pressed && styles.workspaceRowPressed]} + > + + + )} + + + + + {directoryHint} + + {strings.workspaces.type} + + + {backendItems.map((option, index) => { + const chosen = backend === option.value + return ( + setBackend(option.value)} + accessory={ + + {chosen ? : null} + + } + /> + ) + })} + + + + +