diff --git a/packages/app/src/components/agent-status-bar.tsx b/packages/app/src/components/agent-status-bar.tsx index 226c80c0d..501963f7a 100644 --- a/packages/app/src/components/agent-status-bar.tsx +++ b/packages/app/src/components/agent-status-bar.tsx @@ -1,4 +1,4 @@ -import { useCallback, useMemo, useRef, useState } from "react"; +import { memo, useCallback, useMemo, useRef, useState } from "react"; import { View, Text, Platform, Pressable, Keyboard } from "react-native"; import { StyleSheet, useUnistyles } from "react-native-unistyles"; import { useShallow } from "zustand/shallow"; @@ -848,7 +848,11 @@ function ControlledStatusBar({ const EMPTY_MODES: AgentMode[] = []; -export function AgentStatusBar({ agentId, serverId, onDropdownClose }: AgentStatusBarProps) { +export const AgentStatusBar = memo(function AgentStatusBar({ + agentId, + serverId, + onDropdownClose, +}: AgentStatusBarProps) { const { preferences, updatePreferences } = useFormPreferences(); const agent = useSessionStore( useShallow((state) => { @@ -1048,7 +1052,7 @@ export function AgentStatusBar({ agentId, serverId, onDropdownClose }: AgentStat disabled={!client} /> ); -} +}); export function DraftAgentStatusBar({ providerDefinitions, diff --git a/packages/app/src/components/branch-switcher.tsx b/packages/app/src/components/branch-switcher.tsx index c59ea813b..432849389 100644 --- a/packages/app/src/components/branch-switcher.tsx +++ b/packages/app/src/components/branch-switcher.tsx @@ -1,28 +1,45 @@ import { useRef } from "react"; import { Pressable, Text, View } from "react-native"; +import { useQueryClient } from "@tanstack/react-query"; import { ChevronDown, GitBranch } from "lucide-react-native"; import { StyleSheet, useUnistyles } from "react-native-unistyles"; import { Combobox, ComboboxItem, type ComboboxOption } from "@/components/ui/combobox"; +import { useHostRuntimeClient, useHostRuntimeIsConnected } from "@/runtime/host-runtime"; +import { useToast } from "@/contexts/toast-context"; +import { useBranchSwitcher } from "@/hooks/use-branch-switcher"; interface BranchSwitcherProps { currentBranchName: string | null; title: string; - branchOptions: ComboboxOption[]; - isOpen: boolean; - onOpenChange: (open: boolean) => void; - onBranchSelect: (branchId: string) => void; + serverId: string; + workspaceId: string; + isGitCheckout: boolean; } export function BranchSwitcher({ currentBranchName, title, - branchOptions, - isOpen, - onOpenChange, - onBranchSelect, + serverId, + workspaceId, + isGitCheckout, }: BranchSwitcherProps) { const { theme } = useUnistyles(); const anchorRef = useRef(null); + const client = useHostRuntimeClient(serverId); + const isConnected = useHostRuntimeIsConnected(serverId); + const toast = useToast(); + const queryClient = useQueryClient(); + + const { branchOptions, isOpen, setIsOpen, handleBranchSelect } = useBranchSwitcher({ + client, + normalizedServerId: serverId, + normalizedWorkspaceId: workspaceId, + currentBranchName, + isGitCheckout, + isConnected, + toast, + queryClient, + }); if (!currentBranchName) { return ( @@ -36,7 +53,7 @@ export function BranchSwitcher({ onOpenChange(true)} + onPress={() => setIsOpen(true)} style={({ hovered, pressed }) => [ styles.branchSwitcherTrigger, (hovered || pressed) && styles.branchSwitcherTriggerHovered, @@ -53,14 +70,14 @@ export function BranchSwitcher({ state.mobileView); const desktopFileExplorerOpen = usePanelStore((state) => state.desktop.fileExplorerOpen); const toggleFileExplorer = usePanelStore((state) => state.toggleFileExplorer); @@ -1982,10 +1964,9 @@ function WorkspaceScreenContent({ serverId, workspaceId }: WorkspaceScreenProps)