Fix branch switching UI updates and simplify model display

- Use setQueryData for immediate branch switch UI updates
- Replace model selector with SessionStatusIndicator during active streams
- Remove async model name fetching in favor of existing modelString
This commit is contained in:
Chris Scott committed 2025-12-14 18:33:43 -05:00
1 parent 9a1b216125
commit 2c38f7f169
2 files changed
+21 -35

No files matched your search

+19 -33
View File
@@ -15,7 +15,8 @@ import { CommandSuggestions } from '@/components/command/CommandSuggestions'
import { MentionSuggestions, type MentionItem } from './MentionSuggestions'
import { SessionStatusIndicator } from '@/components/ui/session-status-indicator'
import { detectMentionTrigger, parsePromptToParts, getFilename, filterAgentsByQuery } from '@/lib/promptParser'
import { getModel, formatModelName } from '@/api/providers'
import type { components } from '@/api/opencode-types'
import type { MessageWithParts, FileInfo } from '@/api/types'
import {
@@ -55,7 +56,7 @@ export function PromptInput({
onExportSession
}: PromptInputProps) {
const [prompt, setPrompt] = useState('')
const [modelName, setModelName] = useState<string>('')
const [isBashMode, setIsBashMode] = useState(false)
const [showSuggestions, setShowSuggestions] = useState(false)
const [suggestionQuery, setSuggestionQuery] = useState('')
@@ -452,33 +453,16 @@ export function PromptInput({
const modeColor = currentMode === 'plan' ? 'text-yellow-600 dark:text-yellow-500' : 'text-green-600 dark:text-green-500'
const modeBg = currentMode === 'plan' ? 'bg-yellow-500/10 border-yellow-500/30' : 'bg-green-500/10 border-green-500/30'
const { model: selectedModel, modelString } = useModelSelection(opcodeUrl, directory)
const { modelString } = useModelSelection(opcodeUrl, directory)
const currentModel = modelString || ''
const isMobile = useMobile()
const sessionStatus = useSessionStatusForSession(sessionID)
const showStopButton = hasActiveStream && (sessionStatus.type === 'busy' || sessionStatus.type === 'retry')
const hideSecondaryButtons = isMobile && hasActiveStream
useEffect(() => {
const loadModelName = async () => {
if (selectedModel) {
try {
const model = await getModel(selectedModel.providerID, selectedModel.modelID)
if (model) {
setModelName(formatModelName(model))
} else {
setModelName(currentModel)
}
} catch {
setModelName(currentModel)
}
} else {
setModelName('No model selected')
}
}
loadModelName()
}, [selectedModel, currentModel])
useEffect(() => {
if (textareaRef.current && !disabled) {
@@ -490,11 +474,7 @@ export function PromptInput({
return (
<div className="relative backdrop-blur-md bg-background opacity-95 border border-border dark:border-white/30 rounded-xl p-2 md:p-3 md:mx-4 mb-4 md:mb-1 w-[94%] md:max-w-4xl">
{hasActiveStream && (
<div className="pb-1">
<SessionStatusIndicator sessionID={sessionID} />
</div>
)}
<textarea
ref={textareaRef}
@@ -528,12 +508,18 @@ export function PromptInput({
{isBashMode ? 'BASH' : currentMode.toUpperCase()}
</button>
{!hideSecondaryButtons && (
<button
onClick={onShowModelsDialog}
className="px-2 py-1 rounded-md text-xs font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 transition-colors cursor-pointer max-w-[120px] md:max-w-[180px] truncate"
>
{modelName.length > 12 ? modelName.substring(0, 10) + '...' : modelName || 'Select model'}
</button>
hasActiveStream ? (
<div className="px-2 py-1 rounded-md text-xs font-medium border bg-muted border-border text-muted-foreground max-w-[120px] md:max-w-[180px] truncate">
<SessionStatusIndicator sessionID={sessionID} />
</div>
) : (
<button
onClick={onShowModelsDialog}
className="px-2 py-1 rounded-md text-xs font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 transition-colors cursor-pointer max-w-[120px] md:max-w-[180px] truncate"
>
{currentModel.length > 12 ? currentModel.substring(0, 10) + '...' : currentModel || 'Select model'}
</button>
)
)}
{!hideSecondaryButtons && (
<DropdownMenu>
@@ -45,8 +45,8 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
const switchBranchMutation = useMutation({
mutationFn: (branch: string) => switchBranch(repoId, branch),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["repo", repoId] });
onSuccess: (updatedRepo) => {
queryClient.setQueryData(["repo", repoId], updatedRepo);
queryClient.invalidateQueries({ queryKey: ["branches", repoId] });
queryClient.invalidateQueries({ queryKey: ["repos"] });
},