refactor(mobile): group MoreDrawer items and remove command/file mention entries

This commit is contained in:
Chris Scott committed 2026-10-08 00:18:01 -04:00
1 parent 485ab940aa
commit a9331cb484
12 files changed
+114 -257

No files matched your search

@@ -3,7 +3,6 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { render, screen, fireEvent, act, waitFor } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { PromptInput, type PromptInputHandle } from './PromptInput'
import { useUIState } from '@/stores/uiStateStore'
import { BUILTIN_COMMANDS } from '@/lib/builtinCommands'
import { createCommandActionsMock, stubMatchMedia } from '@/test/test-utils'
@@ -209,8 +208,6 @@ describe('PromptInput command submission', () => {
mocks.useSendErrorStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ errors: {} }))
suggestionProps.isOpen = false
suggestionProps.selectedIndex = 0
useUIState.getState().clearPendingPromptCommand()
useUIState.getState().clearPendingPromptFile()
})
afterEach(() => {
@@ -269,13 +266,13 @@ describe('PromptInput command submission', () => {
})
it('sends parsed command attachments and offsets to runCommand without injecting the selected agent', async () => {
mocks.useFileSearch.mockReturnValue({ files: ['src/App.tsx'] })
const { container } = renderComponent()
act(() => {
useUIState.getState().selectPromptFile('src/App.tsx')
})
const input = await screen.findByPlaceholderText('Send a message...')
fireEvent.change(input, { target: { value: '@App' } })
await waitFor(() => expect(suggestionProps.isOpen).toBe(true))
fireEvent.keyDown(input, { key: 'Enter' })
await waitFor(() => expect(input).toHaveValue('@App.tsx '))
await attachImage(container)
@@ -2,7 +2,6 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { PromptInput } from './PromptInput'
import { useUIState } from '@/stores/uiStateStore'
import { createCommandActionsMock, stubMatchMedia } from '@/test/test-utils'
const mocks = vi.hoisted(() => ({
@@ -194,8 +193,6 @@ describe('PromptInput goal mode', () => {
mocks.useUserBash.mockImplementation((selector: (state: unknown) => unknown) => selector({ addUserBashCommand: vi.fn() }))
mocks.useSessionAgentStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ setAgent: mocks.setAgent }))
mocks.useSendErrorStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ errors: {} }))
useUIState.getState().clearPendingPromptCommand()
useUIState.getState().clearPendingPromptFile()
})
afterEach(() => {
@@ -2,7 +2,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { PromptInput } from './PromptInput'
import { useUIState } from '@/stores/uiStateStore'
import { createCommandActionsMock } from '@/test/test-utils'
const mocks = vi.hoisted(() => ({
@@ -194,8 +193,6 @@ describe('PromptInput agent mention submission', () => {
mocks.useSessionAgentStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ setAgent: vi.fn() }))
suggestionProps.isOpen = false
suggestionProps.selectedIndex = 0
useUIState.getState().clearPendingPromptCommand()
useUIState.getState().clearPendingPromptFile()
})
it('sends an @agent mention as an attachment without switching the session agent', async () => {
@@ -2,7 +2,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent, act, waitFor } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { PromptInput } from './PromptInput'
import { useUIState } from '@/stores/uiStateStore'
import { createCommandActionsMock } from '@/test/test-utils'
const createTestQueryClient = () => new QueryClient({
@@ -211,8 +210,6 @@ describe('PromptInput STT Gesture Tests', () => {
mocks.useUserBash.mockImplementation((selector) => selector({ addUserBashCommand: vi.fn() }))
mocks.useSessionAgentStore.mockImplementation((selector) => selector({ setAgent: mockSetAgent }))
mocks.useSendErrorStore.mockImplementation((selector) => selector({ errors: {} }))
useUIState.getState().clearPendingPromptCommand()
useUIState.getState().clearPendingPromptFile()
})
const renderComponent = (sttOverrides: Partial<MockSTTReturn> = {}) => {
@@ -421,33 +418,6 @@ describe('PromptInput STT Gesture Tests', () => {
expect(screen.getAllByTitle('Stop').length).toBeGreaterThan(0)
})
it('inserts a command selected from the mobile drawer', async () => {
renderComponent()
act(() => {
useUIState.getState().selectPromptCommand({
name: 'help',
description: 'Show help',
})
})
await waitFor(() => {
expect(screen.getByPlaceholderText('Send a message...')).toHaveValue('/help ')
})
})
it('inserts a file selected from the mobile drawer', async () => {
renderComponent()
act(() => {
useUIState.getState().selectPromptFile('src/App.tsx')
})
await waitFor(() => {
expect(screen.getByPlaceholderText('Send a message...')).toHaveValue('@App.tsx ')
})
})
it('quick tap starts recording through click only', async () => {
mockStartRecording.mockResolvedValue(true)
@@ -10,7 +10,6 @@ import { useSTT } from '@/hooks/useSTT'
import { useUserBash } from '@/stores/userBashStore'
import { useSessionAgentStore } from '@/stores/sessionAgentStore'
import { useUIState } from '@/stores/uiStateStore'
import { useSendErrorStore } from '@/stores/sendErrorStore'
import { useRecentCommandsStore } from '@/stores/recentCommandsStore'
import { useTouchTapSelect } from '@/hooks/useTouchTapSelect'
@@ -166,10 +165,6 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
const promptRef = useRef(prompt)
const attachedFilesRef = useRef(attachedFiles)
const imageAttachmentsRef = useRef(imageAttachments)
const pendingPromptCommand = useUIState((state) => state.pendingPromptCommand)
const pendingPromptFile = useUIState((state) => state.pendingPromptFile)
const clearPendingPromptCommand = useUIState((state) => state.clearPendingPromptCommand)
const clearPendingPromptFile = useUIState((state) => state.clearPendingPromptFile)
const {
isRecording,
@@ -582,16 +577,10 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
handleSubmitRef.current()
}, [prompt])
useEffect(() => {
if (!pendingPromptCommand) return
handleCommandSelect(pendingPromptCommand.command)
clearPendingPromptCommand()
}, [pendingPromptCommand, handleCommandSelect, clearPendingPromptCommand])
const insertFileMention = useCallback((filePath: string, range: { start: number, end: number } | null = mentionRange) => {
const insertFileMention = useCallback((filePath: string, range: { start: number, end: number }) => {
const filename = getFilename(filePath)
const beforeMention = range ? prompt.slice(0, range.start) : `${prompt}${prompt.trim() ? ' ' : ''}`
const afterMention = range ? prompt.slice(range.end) : ''
const beforeMention = prompt.slice(0, range.start)
const afterMention = prompt.slice(range.end)
const newPrompt = beforeMention + '@' + filename + ' ' + afterMention
setPrompt(newPrompt)
@@ -612,13 +601,7 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
})
focusPromptAt(beforeMention.length + filename.length + 2)
}, [directory, mentionRange, prompt, focusPromptAt])
useEffect(() => {
if (!pendingPromptFile) return
insertFileMention(pendingPromptFile.path, null)
clearPendingPromptFile()
}, [pendingPromptFile, insertFileMention, clearPendingPromptFile])
}, [directory, prompt, focusPromptAt])
const handleMentionSelect = (item: MentionItem) => {
if (!mentionRange || !textareaRef.current) return
@@ -1,29 +1,17 @@
import { render, screen, fireEvent } from '@testing-library/react'
import { render, screen, fireEvent, within } from '@testing-library/react'
import { beforeEach, describe, it, expect, vi } from 'vitest'
import { MemoryRouter, Route, Routes, useNavigate } from 'react-router-dom'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { MoreDrawer } from './MoreDrawer'
import { useAuth } from '@/hooks/useAuth'
import { useServerHealth } from '@/hooks/useServerHealth'
import { useCommands } from '@/hooks/useCommands'
import { useUIState } from '@/stores/uiStateStore'
import { getRepo } from '@/api/repos'
vi.mock('@/hooks/useAuth')
vi.mock('@/hooks/useServerHealth')
vi.mock('@/hooks/useCommands')
vi.mock('@/api/repos', () => ({
getRepo: vi.fn(),
}))
vi.mock('@/components/file-browser/FileBrowserSheet', () => ({
FileBrowserSheet: ({ isOpen, basePath, onFileSelect }: { isOpen: boolean; basePath: string; onFileSelect: (file: { path: string }) => void }) => (
isOpen ? (
<div data-testid="mention-file-browser" data-base-path={basePath}>
<button type="button" onClick={() => onFileSelect({ path: 'repo/src/App.tsx' })}>App.tsx</button>
</div>
) : null
),
}))
vi.mock('react-router-dom', async () => {
const actual = await vi.importActual<typeof import('react-router-dom')>('react-router-dom')
return {
@@ -102,17 +90,6 @@ describe('MoreDrawer', () => {
beforeEach(() => {
vi.clearAllMocks()
vi.mocked(useNavigate).mockReturnValue(vi.fn())
vi.mocked(useCommands).mockReturnValue({
commands: [{ name: 'help', description: 'Show help' }],
recentNames: [],
loading: false,
error: null,
searchCommands: vi.fn(),
findCommand: vi.fn(),
})
useUIState.getState().clearPendingPromptCommand()
useUIState.getState().clearPendingPromptFile()
useUIState.getState().setActivePromptFileBasePath(null)
vi.mocked(getRepo).mockResolvedValue({
id: 1,
localPath: 'wrong-repo',
@@ -192,33 +169,27 @@ describe('MoreDrawer', () => {
expect(screen.queryByText('OpenCode')).not.toBeInTheDocument()
})
it('shows session commands and selects a command', () => {
it('leaves commands and file mentions to the prompt input', () => {
mockAuth()
mockServerHealth()
const handleClose = vi.fn()
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId', onClose: handleClose })
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId' })
fireEvent.click(screen.getByText('Commands'))
expect(screen.queryByText('/help')).not.toBeInTheDocument()
fireEvent.click(screen.getByText('help'))
expect(useUIState.getState().pendingPromptCommand?.command.name).toBe('help')
expect(handleClose).toHaveBeenCalled()
expect(screen.queryByText('Commands')).not.toBeInTheDocument()
expect(screen.queryByText('Mention File')).not.toBeInTheDocument()
})
it('opens file browser and selects a file mention', () => {
it('groups session items into workspace and project sections', () => {
mockAuth()
mockServerHealth()
const handleClose = vi.fn()
useUIState.getState().setActivePromptFileBasePath('repo')
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId', onClose: handleClose })
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId' })
fireEvent.click(screen.getByText('Mention File'))
expect(screen.getByTestId('mention-file-browser')).toHaveAttribute('data-base-path', 'repo')
fireEvent.click(screen.getByText('App.tsx'))
const sectionLabels = (name: string) =>
within(screen.getByRole('region', { name })).getAllByRole('button').map((button) => button.textContent)
expect(useUIState.getState().pendingPromptFile?.path).toBe('src/App.tsx')
expect(handleClose).toHaveBeenCalled()
expect(sectionLabels('Workspace')).toEqual(['Files', 'Source Control', 'Terminal', 'Walkthrough', 'Preview'])
expect(sectionLabels('Project')).toEqual(['MCP', 'Skills', 'Reset Permissions', 'Schedules', 'Actions'])
expect(screen.getAllByText('Settings')).toHaveLength(1)
expect(screen.getAllByText('Logout')).toHaveLength(1)
})
it('shows Assistant instead of the source repo on assistant routes', () => {
+90 -122
View File
@@ -1,21 +1,17 @@
import { useNavigate, useLocation, useParams } from 'react-router-dom'
import { useState, useRef, useEffect } from 'react'
import { ChevronDown, ChevronRight, Command as CommandIcon, FileText, FolderGit2, X, GitBranch } from 'lucide-react'
import { useRef, useEffect, type ReactNode } from 'react'
import { ChevronRight, FolderGit2, X, GitBranch, type LucideIcon } from 'lucide-react'
import { useAuth } from '@/hooks/useAuth'
import { useServerHealth } from '@/hooks/useServerHealth'
import { useCommands } from '@/hooks/useCommands'
import { useUrlParams } from '@/hooks/useUrlParams'
import { useUIState } from '@/stores/uiStateStore'
import { useQuery } from '@tanstack/react-query'
import { getRepo } from '@/api/repos'
import { useRefreshOnOpen } from '@/hooks/useRefreshOnOpen'
import { SideDrawer, SideDrawerContent } from '@/components/ui/side-drawer'
import { FileBrowserSheet } from '@/components/file-browser/FileBrowserSheet'
import { buildMoreItems, buildNavModel, isSessionDetailPath } from './moreDrawerItems'
import { buildMoreItems, buildNavModel, isSessionDetailPath, type MoreDrawerItem } from './moreDrawerItems'
import { useSwipeBack } from '@/hooks/useMobile'
import { getRepoDisplayName } from '@/lib/utils'
import { cn, getRepoDisplayName } from '@/lib/utils'
import { getPathWithReturnTo, isAssistantPath } from '@/lib/navigation'
import type { CommandInfo } from '@opencode-manager/shared/opencode'
import { useMobileTabBar } from '@/hooks/useMobileTabBar'
interface MoreDrawerProps {
@@ -23,13 +19,54 @@ interface MoreDrawerProps {
onClose: () => void
}
const ACCOUNT_ITEM_KEYS: ReadonlySet<string> = new Set(['settings', 'logout'])
const ITEM_GROUPS: ReadonlyArray<{ label: string; keys: ReadonlySet<string> }> = [
{ label: 'Workspace', keys: new Set(['files', 'source-control', 'terminal', 'preview', 'walkthrough']) },
{ label: 'Project', keys: new Set(['mcp', 'skills', 'actions', 'schedules', 'all-schedules', 'reset-permissions']) },
]
function MenuSection({ label, children }: { label?: string; children: ReactNode }) {
return (
<section aria-label={label} className="flex flex-col gap-0.5">
{label && (
<h3 className="px-3 pb-1 text-xs font-medium uppercase tracking-wider text-muted-foreground">{label}</h3>
)}
{children}
</section>
)
}
interface MenuRowProps {
icon: LucideIcon
label: string
onClick: () => void
danger?: boolean
trailing?: boolean
}
function MenuRow({ icon: Icon, label, onClick, danger, trailing }: MenuRowProps) {
return (
<button
type="button"
onClick={onClick}
className={cn(
'flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left transition-colors',
danger ? 'hover:bg-destructive/10' : 'hover:bg-accent',
)}
>
<Icon className={cn('h-5 w-5', danger ? 'text-destructive' : 'text-muted-foreground')} />
<span className={cn('flex-1 font-medium', danger ? 'text-destructive' : 'text-foreground')}>{label}</span>
{trailing && <ChevronRight className="h-4 w-4 text-muted-foreground" />}
</button>
)
}
export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
const navigate = useNavigate()
const location = useLocation()
const { id } = useParams<{ id: string }>()
const repoId = id ? Number(id) : null
const [commandsOpen, setCommandsOpen] = useState(false)
const [mentionFileBrowserOpen, setMentionFileBrowserOpen] = useState(false)
const swipeRef = useRef<HTMLDivElement>(null)
const { bind } = useSwipeBack(onClose, { enabled: isOpen, suspendsRouteSwipe: true })
const { searchParams, updateParams } = useUrlParams()
@@ -38,10 +75,6 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
const isSessionDetail = isSessionDetailPath(location.pathname)
const isAssistantRoute = isAssistantPath(location.pathname)
const isAssistantSession = isSessionDetail && searchParams.get('assistant') === '1'
const { commands } = useCommands({ enabled: isSessionDetail })
const activePromptFileBasePath = useUIState((state) => state.activePromptFileBasePath)
const selectPromptCommand = useUIState((state) => state.selectPromptCommand)
const selectPromptFile = useUIState((state) => state.selectPromptFile)
const { open: openMobileSheet } = useMobileTabBar()
useEffect(() => {
@@ -80,7 +113,15 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
}
}
const handleItemClick = (item: ReturnType<typeof buildMoreItems>[0]) => {
const handleItemClick = (item: MoreDrawerItem) => {
if (item.key === 'settings') {
handleSettingsClick()
return
}
if (item.key === 'logout') {
void handleLogoutClick()
return
}
if (item.to) {
const to = item.key === 'schedules'
? getPathWithReturnTo(item.to, `${location.pathname}${location.search}`)
@@ -94,30 +135,10 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
}
}
const handleCommandClick = (command: CommandInfo) => {
selectPromptCommand(command)
onClose()
}
const getPromptFilePath = (path: string) => {
if (!activePromptFileBasePath) return path
const normalizedPath = path.replace(/^\.\//, '')
const normalizedBasePath = activePromptFileBasePath.replace(/^\.\//, '').replace(/\/+$/, '')
const basePrefix = `${normalizedBasePath}/`
return normalizedPath.startsWith(basePrefix)
? normalizedPath.slice(basePrefix.length)
: normalizedPath
}
const handleFileClick = (path: string) => {
selectPromptFile(getPromptFilePath(path))
setMentionFileBrowserOpen(false)
onClose()
}
const items = buildMoreItems(location.pathname)
const itemsInGroup = (keys: ReadonlySet<string>) => items.filter((item) => keys.has(item.key))
const groupedKeys = new Set([...ACCOUNT_ITEM_KEYS, ...ITEM_GROUPS.flatMap(({ keys }) => [...keys])])
const navigationItems = items.filter((item) => !groupedKeys.has(item.key))
const assistantCta = isSessionDetail && !isAssistantSession
? buildNavModel(location.pathname).primary.find((cta) => cta.key === 'assistant')
: undefined
@@ -161,97 +182,44 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
</div>
)}
</div>
<SideDrawerContent className="flex flex-col gap-1">
{isSessionDetail && (
<div className="flex flex-col gap-1">
<button
type="button"
onClick={() => openMobileSheet('repos')}
className="flex items-center gap-3 p-3 rounded-lg hover:bg-accent transition-colors text-left w-full"
>
<FolderGit2 className="w-5 h-5 text-muted-foreground" />
<span className="font-medium text-foreground flex-1">Repos</span>
<ChevronRight className="w-4 h-4 text-muted-foreground" />
</button>
{assistantCta?.to && (
<button
type="button"
onClick={() => navigate(assistantCta.to!)}
className="flex items-center gap-3 p-3 rounded-lg hover:bg-accent transition-colors text-left w-full"
>
<assistantCta.icon className="w-5 h-5 text-muted-foreground" />
<span className="font-medium text-foreground flex-1">{assistantCta.label}</span>
</button>
)}
<button
type="button"
onClick={() => setCommandsOpen((open) => !open)}
className="flex items-center gap-3 p-3 rounded-lg hover:bg-accent transition-colors text-left w-full"
aria-expanded={commandsOpen}
>
<CommandIcon className="w-5 h-5 text-muted-foreground" />
<span className="font-medium text-foreground flex-1">Commands</span>
{commandsOpen ? (
<ChevronDown className="w-4 h-4 text-muted-foreground" />
) : (
<ChevronRight className="w-4 h-4 text-muted-foreground" />
)}
</button>
{commandsOpen && (
<div className="-mx-4 max-h-64 overflow-y-auto border-y border-border bg-muted/30 p-1 sm:mx-0 sm:rounded-lg sm:border">
{commands.map((command) => (
<button
key={command.name}
type="button"
onClick={() => handleCommandClick(command)}
className="flex w-full min-w-0 items-start gap-3 rounded-md px-3 py-2 text-left transition-colors hover:bg-accent"
>
<span className="font-mono text-sm font-medium text-primary">{command.name}</span>
{command.description && (
<span className="min-w-0 flex-1 truncate text-xs text-muted-foreground">{command.description}</span>
)}
</button>
))}
</div>
)}
<button
type="button"
onClick={() => setMentionFileBrowserOpen(true)}
className="flex items-center gap-3 p-3 rounded-lg hover:bg-accent transition-colors text-left w-full"
>
<FileText className="w-5 h-5 text-muted-foreground" />
<span className="font-medium text-foreground flex-1">Mention File</span>
<ChevronRight className="w-4 h-4 text-muted-foreground" />
</button>
</div>
)}
{items.map((item) => (
<SideDrawerContent className="flex flex-col gap-4 pb-3">
<MenuSection>
{isSessionDetail && (
<MenuRow icon={FolderGit2} label="Repos" onClick={() => openMobileSheet('repos')} trailing />
)}
{assistantCta?.to && (
<MenuRow icon={assistantCta.icon} label={assistantCta.label} onClick={() => navigate(assistantCta.to!)} />
)}
{navigationItems.map((item) => (
<MenuRow key={item.key} icon={item.icon} label={item.label} danger={item.danger} onClick={() => handleItemClick(item)} />
))}
</MenuSection>
{ITEM_GROUPS.map(({ label, keys }) => {
const groupItems = itemsInGroup(keys)
if (groupItems.length === 0) return null
return (
<MenuSection key={label} label={label}>
{groupItems.map((item) => (
<MenuRow key={item.key} icon={item.icon} label={item.label} danger={item.danger} onClick={() => handleItemClick(item)} />
))}
</MenuSection>
)
})}
</SideDrawerContent>
<div className="flex flex-shrink-0 gap-2 border-t border-border bg-background px-4 py-3 pb-[calc(env(safe-area-inset-bottom)+0.75rem)]">
{itemsInGroup(ACCOUNT_ITEM_KEYS).map((item) => (
<button
key={item.key}
type="button"
onClick={() => {
if (item.key === 'settings') {
handleSettingsClick()
} else if (item.key === 'logout') {
handleLogoutClick()
} else {
handleItemClick(item)
}
}}
className="flex items-center gap-3 p-3 rounded-lg hover:bg-accent transition-colors text-left w-full"
onClick={() => handleItemClick(item)}
className="flex flex-1 items-center justify-center gap-2 rounded-lg border border-border p-2.5 text-sm font-medium text-foreground transition-colors hover:bg-accent"
>
<item.icon className="w-5 h-5 text-muted-foreground" />
<span className="font-medium text-foreground">{item.label}</span>
<item.icon className="h-4 w-4 text-muted-foreground" />
{item.label}
</button>
))}
</SideDrawerContent>
</div>
</div>
<FileBrowserSheet
isOpen={mentionFileBrowserOpen}
onClose={() => setMentionFileBrowserOpen(false)}
basePath={activePromptFileBasePath ?? ''}
onFileSelect={(file) => handleFileClick(file.path)}
/>
</SideDrawer>
)
}
-9
View File
@@ -272,7 +272,6 @@ export function SessionDetail() {
const { modelRef } = useModelSelection(sessionDirectory, modelSelectionSession);
const setSessionStatus = useSessionStatus((state) => state.setStatus);
const isEditingMessage = useUIState((state) => state.isEditingMessage);
const setActivePromptFileBasePath = useUIState((state) => state.setActivePromptFileBasePath);
const { isEnabled: ttsEnabled } = useTTS();
const { syncForSession: syncPermissionsForSession } = usePermissions();
const { getForSession: getFormForSession, reply: replyToForm, cancel: cancelForm, syncForSession: syncFormsForSession } = useForms();
@@ -292,14 +291,6 @@ export function SessionDetail() {
const isStreamingResponse = hasIncompleteMessages && isSessionActive;
const workspaceBasePath = repo?.localPath;
useEffect(() => {
setActivePromptFileBasePath(sessionDirectory ? workspaceBasePath ?? null : null)
return () => {
setActivePromptFileBasePath(null)
}
}, [sessionDirectory, setActivePromptFileBasePath, workspaceBasePath])
useAutoPlayLastResponse({
sessionId: sessionId ?? '',
lastAssistantMessage,
@@ -147,7 +147,7 @@ vi.mock('@/hooks/useAutoPlayLastResponse', () => ({
vi.mock('@/stores/uiStateStore', () => ({
useUIState: vi.fn((selector?: (state: Record<string, unknown>) => unknown) =>
typeof selector === 'function'
? selector({ isEditingMessage: false, setActivePromptFileBasePath: vi.fn() })
? selector({ isEditingMessage: false })
: false
),
}))
@@ -107,7 +107,7 @@ vi.mock('@/hooks/useAutoPlayLastResponse', () => ({
vi.mock('@/stores/uiStateStore', () => ({
useUIState: vi.fn((selector?: (state: Record<string, unknown>) => unknown) =>
typeof selector === 'function'
? selector({ isEditingMessage: false, setActivePromptFileBasePath: vi.fn() })
? selector({ isEditingMessage: false })
: false
),
}))
@@ -102,7 +102,7 @@ vi.mock('@/hooks/useAutoPlayLastResponse', () => ({
vi.mock('@/stores/uiStateStore', () => ({
useUIState: vi.fn((selector?: (state: Record<string, unknown>) => unknown) =>
typeof selector === 'function'
? selector({ isEditingMessage: mocks.uiState.isEditingMessage, setActivePromptFileBasePath: vi.fn() })
? selector({ isEditingMessage: mocks.uiState.isEditingMessage })
: false
),
}))
-17
View File
@@ -1,28 +1,11 @@
import { create } from 'zustand'
import type { CommandInfo } from '@opencode-manager/shared/opencode'
interface UIStateStore {
isEditingMessage: boolean
activePromptFileBasePath: string | null
pendingPromptCommand: { id: number; command: CommandInfo } | null
pendingPromptFile: { id: number; path: string } | null
setIsEditingMessage: (isEditing: boolean) => void
setActivePromptFileBasePath: (basePath: string | null) => void
selectPromptCommand: (command: CommandInfo) => void
clearPendingPromptCommand: () => void
selectPromptFile: (path: string) => void
clearPendingPromptFile: () => void
}
export const useUIState = create<UIStateStore>((set) => ({
isEditingMessage: false,
activePromptFileBasePath: null,
pendingPromptCommand: null,
pendingPromptFile: null,
setIsEditingMessage: (isEditing: boolean) => set({ isEditingMessage: isEditing }),
setActivePromptFileBasePath: (basePath: string | null) => set({ activePromptFileBasePath: basePath }),
selectPromptCommand: (command: CommandInfo) => set({ pendingPromptCommand: { id: Date.now(), command } }),
clearPendingPromptCommand: () => set({ pendingPromptCommand: null }),
selectPromptFile: (path: string) => set({ pendingPromptFile: { id: Date.now(), path } }),
clearPendingPromptFile: () => set({ pendingPromptFile: null }),
}))