mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
feat(frontend): move send to the input and show key bar in the controls row
- Place Send/Queue/View at the end of the textarea and hide Send when the draft is empty - Keep the model picker visible on mobile while a session is active - Keep the mobile mic in the controls row alongside Send - Show the /, @, ! keys in place of the agent/model selectors while focused on mobile - Compact the mobile controls row while the prompt is focused
This commit is contained in:
1 parent
332fb07f45
commit
76d52b3550
6 files changed
+449
-118
No files matched your search
@@ -249,27 +249,22 @@ describe('ComposerToolsMenu', () => {
|
||||
expect(props.onAttachFile).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('omits the dictate item when onDictate is not provided', async () => {
|
||||
const user = userEvent.setup()
|
||||
it('uses the default control size for the trigger', () => {
|
||||
mockPermissionMode()
|
||||
renderMenu()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Composer options' }))
|
||||
await screen.findByRole('menuitem', { name: 'Attach image or PDF' })
|
||||
|
||||
expect(screen.queryByRole('menuitem', { name: 'Dictate' })).not.toBeInTheDocument()
|
||||
const trigger = screen.getByRole('button', { name: 'Composer options' })
|
||||
expect(trigger).toHaveClass('min-h-[44px]', 'min-w-[44px]')
|
||||
expect(trigger).not.toHaveClass('min-h-9')
|
||||
})
|
||||
|
||||
it('starts dictation when onDictate is provided', async () => {
|
||||
const user = userEvent.setup()
|
||||
it('uses the compact control size for the trigger while the composer is focused', () => {
|
||||
mockPermissionMode()
|
||||
const onDictate = vi.fn()
|
||||
renderMenu({ onDictate })
|
||||
renderMenu({ compact: true })
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Composer options' }))
|
||||
await user.click(await screen.findByRole('menuitem', { name: 'Dictate' }))
|
||||
|
||||
expect(onDictate).toHaveBeenCalledTimes(1)
|
||||
const trigger = screen.getByRole('button', { name: 'Composer options' })
|
||||
expect(trigger).toHaveClass('min-h-9', 'min-w-9')
|
||||
expect(trigger).not.toHaveClass('min-h-[44px]')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState } from 'react'
|
||||
import { Mic, Paperclip, Plus, Shield, ShieldCheck, Target } from 'lucide-react'
|
||||
import { Paperclip, Plus, Shield, ShieldCheck, Target } from 'lucide-react'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuCheckboxItem,
|
||||
@@ -25,9 +25,17 @@ interface ComposerToolsMenuProps {
|
||||
goalLabel: string
|
||||
onToggleGoal: () => void
|
||||
onAttachFile: () => void
|
||||
onDictate?: () => void
|
||||
/** Uses the 36px control size for the trigger while the prompt is focused. */
|
||||
compact?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the mobile composer tools trigger: a dropdown for permission mode,
|
||||
* sandboxing, goal mode, and file attachment.
|
||||
*
|
||||
* @param props Session context, goal state, the attach handler, and whether the
|
||||
* trigger uses the compact 36px control size while the prompt is focused.
|
||||
*/
|
||||
export function ComposerToolsMenu({
|
||||
sessionID,
|
||||
directory,
|
||||
@@ -36,7 +44,7 @@ export function ComposerToolsMenu({
|
||||
goalLabel,
|
||||
onToggleGoal,
|
||||
onAttachFile,
|
||||
onDictate,
|
||||
compact = false,
|
||||
}: ComposerToolsMenuProps) {
|
||||
const isLocalServer = isLocalOpenCodeServer(useOpenCodeServerId())
|
||||
const permission = usePermissionModeToggle(sessionID, directory)
|
||||
@@ -51,7 +59,7 @@ export function ComposerToolsMenu({
|
||||
type="button"
|
||||
aria-label="Composer options"
|
||||
title="Composer options"
|
||||
className={`${getIconToggleButtonClassName(permission.isAuto || sandbox.isSandboxed || goalArmed)} flex items-center justify-center min-h-[44px] min-w-[44px]`}
|
||||
className={`${getIconToggleButtonClassName(permission.isAuto || sandbox.isSandboxed || goalArmed)} flex items-center justify-center ${compact ? 'min-h-9 min-w-9' : 'min-h-[44px] min-w-[44px]'}`}
|
||||
>
|
||||
<Plus className="w-5 h-5" />
|
||||
</button>
|
||||
@@ -82,11 +90,6 @@ export function ComposerToolsMenu({
|
||||
<DropdownMenuItem onSelect={onAttachFile} className="pl-8">
|
||||
<ToolMenuItemContent icon={<Paperclip className="h-4 w-4" />} title="Attach image or PDF" />
|
||||
</DropdownMenuItem>
|
||||
{onDictate ? (
|
||||
<DropdownMenuItem onSelect={onDictate} className="pl-8">
|
||||
<ToolMenuItemContent icon={<Mic className="h-4 w-4" />} title="Dictate" />
|
||||
</DropdownMenuItem>
|
||||
) : null}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
{shouldShowSandboxResources(sandbox) ? (
|
||||
|
||||
@@ -581,7 +581,7 @@ describe('PromptInput command submission', () => {
|
||||
renderComponent()
|
||||
|
||||
const input = await screen.findByPlaceholderText('Send a message...')
|
||||
const frame = input.parentElement as HTMLElement
|
||||
const frame = input.closest('.isolate') as HTMLElement
|
||||
const tokens = frame.className.split(/\s+/)
|
||||
|
||||
expect(tokens).not.toContain('transition-all')
|
||||
|
||||
@@ -0,0 +1,331 @@
|
||||
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 { createCommandActionsMock } from '@/test/test-utils'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
useSTT: vi.fn(),
|
||||
useMobile: vi.fn(),
|
||||
useCommands: vi.fn(),
|
||||
useCommandHandler: vi.fn(),
|
||||
useFileSearch: vi.fn(),
|
||||
useModelSelection: vi.fn(),
|
||||
useVariants: vi.fn(),
|
||||
useSessionAgent: vi.fn(),
|
||||
useUserBash: vi.fn(),
|
||||
useSessionAgentStore: vi.fn(),
|
||||
useSendErrorStore: vi.fn(),
|
||||
useHasBackgroundActivity: vi.fn(),
|
||||
useSendPrompt: vi.fn(),
|
||||
hasPendingPermission: vi.fn(() => false),
|
||||
setShowDialog: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSTT', () => ({ useSTT: mocks.useSTT }))
|
||||
vi.mock('@/hooks/useMobile', () => ({ useMobile: mocks.useMobile }))
|
||||
vi.mock('@/hooks/useCommands', () => ({ useCommands: mocks.useCommands }))
|
||||
vi.mock('@/hooks/useCommandHandler', () => ({ useCommandHandler: mocks.useCommandHandler }))
|
||||
vi.mock('@/hooks/useFileSearch', () => ({ useFileSearch: mocks.useFileSearch }))
|
||||
vi.mock('@/hooks/useModelSelection', () => ({ useModelSelection: mocks.useModelSelection }))
|
||||
vi.mock('@/hooks/useVariants', () => ({ useVariants: mocks.useVariants }))
|
||||
vi.mock('@/hooks/useSessionAgent', () => ({ useSessionAgent: mocks.useSessionAgent }))
|
||||
vi.mock('@/stores/userBashStore', () => ({ useUserBash: mocks.useUserBash }))
|
||||
vi.mock('@/stores/sessionAgentStore', () => ({ useSessionAgentStore: mocks.useSessionAgentStore }))
|
||||
vi.mock('@/stores/sendErrorStore', () => ({ useSendErrorStore: mocks.useSendErrorStore }))
|
||||
vi.mock('@/stores/sessionStatusStore', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/stores/sessionStatusStore')>()
|
||||
return { ...actual, useHasBackgroundActivity: mocks.useHasBackgroundActivity }
|
||||
})
|
||||
vi.mock('@/lib/toast', () => ({
|
||||
showToast: { success: vi.fn(), error: vi.fn(), info: vi.fn(), warning: vi.fn(), loading: vi.fn(), promise: vi.fn(), dismiss: vi.fn() },
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useOpenCode', () => ({
|
||||
useSendPrompt: () => ({ mutate: mocks.useSendPrompt, isPending: false }),
|
||||
useInterruptSession: () => ({ mutate: vi.fn() }),
|
||||
useSendShell: () => ({ mutate: vi.fn(), isPending: false }),
|
||||
useAgents: () => ({ data: [] }),
|
||||
useSkills: () => ({ data: [] }),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useProviders', () => ({ useProviders: () => ({ data: undefined }) }))
|
||||
|
||||
vi.mock('@/contexts/EventContext', () => ({
|
||||
usePermissions: () => ({
|
||||
hasForSession: mocks.hasPendingPermission,
|
||||
setShowDialog: mocks.setShowDialog,
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock('@/components/agent/AgentQuickSelect', () => ({
|
||||
AgentQuickSelect: () => <div data-testid="agent-quick-select" />,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/model/ModelQuickSelect', () => ({
|
||||
ModelQuickSelect: ({ children }: { children?: React.ReactNode }) => (
|
||||
<div data-testid="model-quick-select">{children}</div>
|
||||
),
|
||||
}))
|
||||
|
||||
vi.mock('@/components/session/PermissionModeToggle', () => ({ PermissionModeToggle: () => null }))
|
||||
vi.mock('@/components/session/SessionSandboxMenu', () => ({ SessionSandboxMenu: () => null }))
|
||||
vi.mock('./ComposerToolsMenu', () => ({
|
||||
ComposerToolsMenu: ({ compact }: { compact?: boolean }) => (
|
||||
<div data-testid="composer-tools-menu" data-compact={compact ? 'true' : 'false'} />
|
||||
),
|
||||
}))
|
||||
vi.mock('./PromptSuggestions', () => ({ PromptSuggestions: () => null }))
|
||||
vi.mock('@/hooks/useSessionGoals', () => ({
|
||||
useSessionGoal: () => ({ data: undefined }),
|
||||
useStartSessionGoal: () => ({ mutateAsync: vi.fn(), isPending: false }),
|
||||
}))
|
||||
vi.mock('@/hooks/useSessionPermissionMode', () => ({ useSessionPermissionMode: () => ({ data: undefined }) }))
|
||||
|
||||
const createTestQueryClient = () => new QueryClient({
|
||||
defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
|
||||
})
|
||||
|
||||
const defaultProps = {
|
||||
directory: '/test',
|
||||
sessionID: 'test-session',
|
||||
showScrollButton: false,
|
||||
isSessionActive: false,
|
||||
isStreamingResponse: false,
|
||||
onScrollToBottom: vi.fn(),
|
||||
commandActions: createCommandActionsMock(),
|
||||
onPromptChange: vi.fn(),
|
||||
}
|
||||
|
||||
describe('PromptInput composer layout', () => {
|
||||
const renderComponent = (overrides: Partial<typeof defaultProps> = {}) => render(
|
||||
<QueryClientProvider client={createTestQueryClient()}>
|
||||
<PromptInput {...defaultProps} {...overrides} />
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
const promptInput = () => screen.getByPlaceholderText('Send a message...')
|
||||
const submitButton = () => document.querySelector('[data-submit-prompt]')
|
||||
const controlsRow = () => screen.getByTestId('composer-controls-row')
|
||||
const mobileVoiceButton = () => document.querySelector('[data-voice-variant="mobile"]')
|
||||
const keyButtons = () => screen.queryAllByRole('toolbar', { name: 'Insert' })
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mocks.hasPendingPermission.mockReturnValue(false)
|
||||
mocks.useMobile.mockReturnValue(false)
|
||||
mocks.useSTT.mockReturnValue({
|
||||
isRecording: false,
|
||||
isProcessing: false,
|
||||
isSupported: true,
|
||||
isEnabled: true,
|
||||
interimTranscript: '',
|
||||
transcript: '',
|
||||
startRecording: vi.fn(),
|
||||
stopRecording: vi.fn(),
|
||||
abortRecording: vi.fn(),
|
||||
reset: vi.fn(),
|
||||
clear: vi.fn(),
|
||||
})
|
||||
mocks.useCommands.mockReturnValue({ searchCommands: () => [], findCommand: vi.fn(), recentNames: [] })
|
||||
mocks.useCommandHandler.mockReturnValue({ executeCommand: vi.fn() })
|
||||
mocks.useFileSearch.mockReturnValue({ files: [] })
|
||||
mocks.useModelSelection.mockReturnValue({
|
||||
model: null,
|
||||
modelString: 'test-model',
|
||||
setModel: vi.fn(),
|
||||
setActiveAgent: vi.fn(),
|
||||
recentModels: [],
|
||||
favoriteModels: [],
|
||||
toggleFavorite: vi.fn(),
|
||||
isModelReady: true,
|
||||
})
|
||||
mocks.useVariants.mockReturnValue({ hasVariants: false, currentVariant: null, cycleVariant: vi.fn() })
|
||||
mocks.useSessionAgent.mockReturnValue({ agent: 'default' })
|
||||
mocks.useUserBash.mockImplementation((selector: (state: unknown) => unknown) => selector({ addUserBashCommand: vi.fn() }))
|
||||
mocks.useSessionAgentStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ setAgent: vi.fn() }))
|
||||
mocks.useSendErrorStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ errors: {} }))
|
||||
mocks.useHasBackgroundActivity.mockReturnValue(false)
|
||||
})
|
||||
|
||||
describe('primary action placement', () => {
|
||||
it('omits the submit button while the prompt is empty', () => {
|
||||
renderComponent()
|
||||
|
||||
expect(promptInput()).toBeInTheDocument()
|
||||
expect(submitButton()).toBeNull()
|
||||
})
|
||||
|
||||
it('renders the submit button after the textarea in the same row', () => {
|
||||
renderComponent()
|
||||
|
||||
fireEvent.change(promptInput(), { target: { value: 'hello' } })
|
||||
|
||||
const textarea = promptInput()
|
||||
const button = submitButton() as HTMLElement
|
||||
|
||||
expect(button).not.toBeNull()
|
||||
expect(button.parentElement).toBe(textarea.parentElement)
|
||||
expect(textarea.nextElementSibling).toBe(button)
|
||||
expect(button.parentElement?.contains(controlsRow())).toBe(false)
|
||||
})
|
||||
|
||||
it('sends the typed prompt from the row button', () => {
|
||||
renderComponent()
|
||||
|
||||
fireEvent.change(promptInput(), { target: { value: 'row send' } })
|
||||
fireEvent.click(screen.getByTitle('Send'))
|
||||
|
||||
const [variables] = mocks.useSendPrompt.mock.calls[0] as [{ text: string }]
|
||||
expect(variables.text).toBe('row send')
|
||||
})
|
||||
|
||||
it('queues from the row button while a response streams', () => {
|
||||
renderComponent({ isStreamingResponse: true })
|
||||
|
||||
fireEvent.change(promptInput(), { target: { value: 'follow-up' } })
|
||||
|
||||
expect(screen.getByTitle('Queue message')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows View for a pending permission even while the prompt is empty', () => {
|
||||
mocks.hasPendingPermission.mockReturnValue(true)
|
||||
renderComponent()
|
||||
|
||||
const view = screen.getByTitle('View pending permission')
|
||||
expect(view).toHaveTextContent('View')
|
||||
expect(view).toHaveAttribute('data-submit-prompt')
|
||||
expect(view.parentElement).toBe(promptInput().parentElement)
|
||||
|
||||
fireEvent.click(view)
|
||||
expect(mocks.setShowDialog).toHaveBeenCalledWith(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('model visibility', () => {
|
||||
it('keeps the model selector visible on mobile while the session is active', () => {
|
||||
mocks.useMobile.mockReturnValue(true)
|
||||
renderComponent({ isSessionActive: true })
|
||||
|
||||
expect(screen.getByTestId('model-quick-select')).toBeInTheDocument()
|
||||
expect(screen.getByText('test-model')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('keeps the model selector visible on desktop while the session is active', () => {
|
||||
renderComponent({ isSessionActive: true })
|
||||
|
||||
expect(screen.getByTestId('model-quick-select')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('mobile key bar', () => {
|
||||
beforeEach(() => {
|
||||
mocks.useMobile.mockReturnValue(true)
|
||||
})
|
||||
|
||||
it('replaces the agent and model selectors with keys in the controls row while focused', () => {
|
||||
renderComponent()
|
||||
|
||||
expect(keyButtons()).toHaveLength(0)
|
||||
expect(screen.getByTestId('agent-quick-select')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('model-quick-select')).toBeInTheDocument()
|
||||
|
||||
fireEvent.focus(promptInput())
|
||||
|
||||
expect(keyButtons()).toHaveLength(1)
|
||||
expect(controlsRow().firstElementChild).toContainElement(keyButtons()[0])
|
||||
expect(screen.getByRole('button', { name: 'cmd /' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'mention @' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'bash !' })).toBeInTheDocument()
|
||||
expect(screen.queryByTestId('agent-quick-select')).not.toBeInTheDocument()
|
||||
expect(screen.queryByTestId('model-quick-select')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('restores the agent and model selectors after the prompt blurs', async () => {
|
||||
renderComponent()
|
||||
|
||||
fireEvent.focus(promptInput())
|
||||
expect(screen.queryByTestId('model-quick-select')).not.toBeInTheDocument()
|
||||
|
||||
fireEvent.blur(promptInput())
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole('toolbar', { name: 'Insert' })).not.toBeInTheDocument()
|
||||
})
|
||||
expect(screen.getByTestId('agent-quick-select')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('model-quick-select')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('replaces the mobile Latest button with keys while focused', () => {
|
||||
renderComponent({ showScrollButton: true })
|
||||
|
||||
expect(screen.getByText('Latest')).toBeInTheDocument()
|
||||
|
||||
fireEvent.focus(promptInput())
|
||||
|
||||
expect(screen.queryByText('Latest')).not.toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'cmd /' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('keeps the voice button and composer tools on the right side of the controls row', () => {
|
||||
renderComponent()
|
||||
|
||||
fireEvent.focus(promptInput())
|
||||
|
||||
const actions = controlsRow().lastElementChild as HTMLElement
|
||||
expect(actions).toContainElement(mobileVoiceButton() as HTMLElement)
|
||||
expect(actions).toContainElement(screen.getByTestId('composer-tools-menu'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('mobile voice button', () => {
|
||||
beforeEach(() => {
|
||||
mocks.useMobile.mockReturnValue(true)
|
||||
})
|
||||
|
||||
it('renders the mobile mic alongside Send when the prompt has content', () => {
|
||||
renderComponent()
|
||||
|
||||
fireEvent.change(promptInput(), { target: { value: 'hello' } })
|
||||
|
||||
expect(submitButton()).not.toBeNull()
|
||||
expect(mobileVoiceButton()).not.toBeNull()
|
||||
expect(controlsRow().lastElementChild).toContainElement(mobileVoiceButton() as HTMLElement)
|
||||
})
|
||||
|
||||
it('hides the mic while a permission is pending', () => {
|
||||
mocks.hasPendingPermission.mockReturnValue(true)
|
||||
renderComponent()
|
||||
|
||||
expect(mobileVoiceButton()).toBeNull()
|
||||
expect(screen.getByTitle('View pending permission')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('compact controls', () => {
|
||||
it('uses compact sizing for the key buttons and mic while focused on mobile', () => {
|
||||
mocks.useMobile.mockReturnValue(true)
|
||||
renderComponent()
|
||||
|
||||
fireEvent.focus(promptInput())
|
||||
|
||||
const commandKey = screen.getByRole('button', { name: 'cmd /' })
|
||||
expect(commandKey).toHaveClass('min-h-9')
|
||||
expect(commandKey).not.toHaveClass('min-h-[44px]')
|
||||
|
||||
const mic = mobileVoiceButton() as HTMLElement
|
||||
expect(mic).toHaveClass('min-h-9', 'min-w-9')
|
||||
expect(mic).not.toHaveClass('min-h-[44px]')
|
||||
expect(screen.getByTestId('composer-tools-menu')).toHaveAttribute('data-compact', 'true')
|
||||
})
|
||||
|
||||
it('uses the default sizing while the prompt is not focused', () => {
|
||||
mocks.useMobile.mockReturnValue(true)
|
||||
renderComponent()
|
||||
|
||||
const mic = mobileVoiceButton() as HTMLElement
|
||||
expect(mic).toHaveClass('min-h-[44px]', 'min-w-[44px]')
|
||||
expect(screen.getByTestId('composer-tools-menu')).toHaveAttribute('data-compact', 'false')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -571,13 +571,13 @@ describe('PromptInput STT Gesture Tests', () => {
|
||||
expect(screen.queryByTitle('Send')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows the submit button and hides the mobile mic once the prompt has content', () => {
|
||||
it('shows the submit button and keeps the mobile mic once the prompt has content', () => {
|
||||
renderComponent()
|
||||
|
||||
fireEvent.change(screen.getByPlaceholderText('Send a message...'), { target: { value: 'hello' } })
|
||||
|
||||
expect(screen.getByTitle('Send')).toBeInTheDocument()
|
||||
expect(queryMobileVoiceButton()).toBeNull()
|
||||
expect(queryMobileVoiceButton()).not.toBeNull()
|
||||
})
|
||||
|
||||
it('keeps the mobile mic visible while recording even with prompt content', () => {
|
||||
|
||||
@@ -1340,7 +1340,6 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
|
||||
const composerModeStyle = composerMode ? COMPOSER_MODE_STYLES[composerMode] : null
|
||||
const isTakeoverOpen = isMobile && (isCommandListOpen || isMentionListOpen)
|
||||
const showStopButton = isSessionActive
|
||||
const hideSecondaryButtons = isMobile && isSessionActive
|
||||
const showMobileScrollButton = isMobile && showScrollButton
|
||||
const hasOpenGoal = isOpenSessionGoal(sessionGoal)
|
||||
const lockedReason = permissionMode?.lockedReason ?? null
|
||||
@@ -1371,7 +1370,8 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
|
||||
const showVoiceFeedback = voiceFeedbackState !== null
|
||||
const hasPromptContent = prompt.trim().length > 0 || imageAttachments.length > 0
|
||||
const canUseMobileVoice = isMobile && sttEnabled && sttSupported && !hasPendingPermissionForSession
|
||||
const showMobileVoiceButton = canUseMobileVoice && (!hasPromptContent || showVoiceFeedback)
|
||||
const compactControls = isMobile && isPromptFocused
|
||||
const showMobileKeys = isMobile && isPromptFocused && !hasPendingPermissionForSession
|
||||
const voiceFeedbackLabel = voiceFeedbackState === 'starting'
|
||||
? 'Starting microphone...'
|
||||
: voiceFeedbackState === 'sending'
|
||||
@@ -1414,13 +1414,13 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
|
||||
? 'bg-destructive hover:bg-destructive/90 text-destructive-foreground border-destructive/60 animate-pulse'
|
||||
: 'bg-muted hover:bg-muted-foreground/20 text-muted-foreground hover:text-foreground border-border'
|
||||
}`
|
||||
: `px-4 min-h-[44px] min-w-[56px] rounded-lg transition-all duration-150 flex items-center justify-center border touch-none select-none ${
|
||||
: `${compactControls ? 'min-h-9 min-w-9 px-0' : 'min-h-[44px] min-w-[44px] px-0'} rounded-lg transition-all duration-150 flex items-center justify-center border touch-none select-none ${
|
||||
isBusy
|
||||
? 'bg-success text-success-foreground border-success/70 shadow-lg shadow-success/40'
|
||||
: 'bg-muted hover:bg-muted-foreground/20 text-muted-foreground hover:text-foreground border-border active:bg-muted-foreground/30 active:scale-95'
|
||||
}`
|
||||
|
||||
const containerClassName = isDesktop ? 'relative hidden md:block' : 'relative flex w-full justify-end touch-none select-none'
|
||||
const containerClassName = isDesktop ? 'relative hidden md:block' : 'relative flex touch-none select-none'
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -1454,6 +1454,41 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
|
||||
)
|
||||
}
|
||||
|
||||
const renderMobileKeys = () => (
|
||||
<div role="toolbar" aria-label="Insert" className="flex flex-nowrap items-center gap-1.5 min-w-0">
|
||||
{KEYBAR_KEYS.map((key) => {
|
||||
const isActive = key.id === 'command'
|
||||
? showSuggestions
|
||||
: key.id === 'mention'
|
||||
? showMentionSuggestions
|
||||
: isBashMode
|
||||
const isDisabled = key.id === 'bash' ? !isBashKeyEnabled : isBashMode
|
||||
return (
|
||||
<button
|
||||
key={key.id}
|
||||
type="button"
|
||||
aria-pressed={isActive}
|
||||
aria-label={`${key.label} ${key.symbol}`}
|
||||
disabled={isDisabled}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onTouchStart={keybarTouch.onTouchStart}
|
||||
onTouchMove={keybarTouch.onTouchMove}
|
||||
onTouchEnd={(e) => keybarTouch.onTouchEnd(e, key.id)}
|
||||
onClick={() => keybarTouch.onClick(key.id)}
|
||||
className={`flex items-center gap-1 min-w-0 rounded-lg border font-mono text-base font-bold transition-colors disabled:opacity-30 ${
|
||||
compactControls ? 'min-h-9 px-2' : 'min-h-[44px] px-3'
|
||||
} ${
|
||||
isActive ? COMPOSER_MODE_STYLES[key.id].key : 'bg-muted border-border text-foreground active:bg-muted-foreground/20'
|
||||
}`}
|
||||
>
|
||||
{key.symbol}
|
||||
<span className="truncate font-sans text-[11px] font-medium opacity-80">{key.label}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1501,30 +1536,47 @@ return (
|
||||
{composerModeStyle.label}
|
||||
</span>
|
||||
)}
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
data-prompt-input
|
||||
value={prompt}
|
||||
onChange={handleInput}
|
||||
onFocus={handlePromptFocus}
|
||||
onBlur={handlePromptBlur}
|
||||
onKeyDown={handleKeyDown}
|
||||
onPaste={handlePaste}
|
||||
onDragOver={handleDragOver}
|
||||
onDragLeave={handleDragLeave}
|
||||
onDrop={handleDrop}
|
||||
placeholder={
|
||||
isBashMode
|
||||
? "Enter bash command..."
|
||||
: "Send a message..."
|
||||
}
|
||||
className={`w-full bg-muted/50 pl-2 md:pl-3 pr-3 py-2 text-[16px] text-foreground placeholder-muted-foreground focus:outline-none focus:bg-muted/70 resize-none min-h-[40px] max-h-[120px] disabled:opacity-50 disabled:cursor-not-allowed md:text-sm rounded-lg [field-sizing:content] ${
|
||||
isBashMode
|
||||
? 'border-warning/50 bg-warning/5 focus:bg-warning/10'
|
||||
: isDragging ? 'border-info/50 border-dashed bg-info/5' : ''
|
||||
}`}
|
||||
rows={1}
|
||||
/>
|
||||
<div className="flex items-end gap-1.5 md:gap-2">
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
data-prompt-input
|
||||
value={prompt}
|
||||
onChange={handleInput}
|
||||
onFocus={handlePromptFocus}
|
||||
onBlur={handlePromptBlur}
|
||||
onKeyDown={handleKeyDown}
|
||||
onPaste={handlePaste}
|
||||
onDragOver={handleDragOver}
|
||||
onDragLeave={handleDragLeave}
|
||||
onDrop={handleDrop}
|
||||
placeholder={
|
||||
isBashMode
|
||||
? "Enter bash command..."
|
||||
: "Send a message..."
|
||||
}
|
||||
className={`flex-1 min-w-0 bg-muted/50 pl-2 md:pl-3 pr-3 py-2 text-[16px] text-foreground placeholder-muted-foreground focus:outline-none focus:bg-muted/70 resize-none min-h-[40px] max-h-[120px] disabled:opacity-50 disabled:cursor-not-allowed md:text-sm rounded-lg [field-sizing:content] ${
|
||||
isBashMode
|
||||
? 'border-warning/50 bg-warning/5 focus:bg-warning/10'
|
||||
: isDragging ? 'border-info/50 border-dashed bg-info/5' : ''
|
||||
}`}
|
||||
rows={1}
|
||||
/>
|
||||
{(hasPendingPermissionForSession || hasPromptContent) && (
|
||||
<button
|
||||
data-submit-prompt
|
||||
onClick={hasPendingPermissionForSession ? () => setShowDialog(true) : handleSubmit}
|
||||
disabled={hasPendingPermissionForSession ? false : (!isModelReady || !hasPromptContent || (isPromptSubmitPending && !isStreamingResponse))}
|
||||
className={`px-4 md:px-5 py-1.5 md:py-2 rounded-lg text-sm font-medium transition-colors dark:border flex-shrink-0 min-w-[52px] flex items-center justify-center min-h-[44px] md:min-h-0 ${
|
||||
hasPendingPermissionForSession
|
||||
? 'bg-highlight hover:bg-highlight/90 border-highlight text-highlight-foreground ring-highlight/20'
|
||||
: 'bg-primary hover:bg-primary/90 disabled:bg-muted disabled:text-muted-foreground disabled:cursor-not-allowed text-primary-foreground border-border/30'
|
||||
}`}
|
||||
title={hasPendingPermissionForSession ? 'View pending permission' : (isStreamingResponse ? 'Queue message' : 'Send')}
|
||||
>
|
||||
<span className="whitespace-nowrap">{hasPendingPermissionForSession ? 'View' : (isStreamingResponse ? 'Queue' : 'Send')}</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{imageAttachments.length > 0 && (
|
||||
<div className="flex flex-wrap gap-2 px-2 py-2 mb-2">
|
||||
@@ -1546,14 +1598,14 @@ return (
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex gap-1.5 md:gap-2 items-center justify-between">
|
||||
<div data-testid="composer-controls-row" className="flex gap-1.5 md:gap-2 items-center justify-between">
|
||||
<div className="flex flex-1 md:flex-initial gap-1.5 md:gap-2 items-center min-w-0">
|
||||
{showMobileScrollButton ? (
|
||||
{showMobileKeys ? renderMobileKeys() : showMobileScrollButton ? (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onScrollToBottom}
|
||||
className="flex items-center gap-1.5 px-3 min-h-[44px] rounded-lg text-xs font-medium border bg-background/80 hover:bg-accent/90 text-primary hover:text-primary-hover border-primary/20 shadow-md backdrop-blur-md transition-all duration-200 active:scale-95 ring-1 ring-primary/15"
|
||||
className={`flex items-center gap-1.5 px-3 rounded-lg text-xs font-medium border bg-background/80 hover:bg-accent/90 text-primary hover:text-primary-hover border-primary/20 shadow-md backdrop-blur-md transition-all duration-200 active:scale-95 ring-1 ring-primary/15 ${compactControls ? 'min-h-9' : 'min-h-[44px]'}`}
|
||||
title="Scroll to bottom"
|
||||
aria-label="Scroll to bottom"
|
||||
>
|
||||
@@ -1595,21 +1647,19 @@ return (
|
||||
onOpenChange={setIsModelPickerOpen}
|
||||
session={modelSelectionSession}
|
||||
>
|
||||
{!hideSecondaryButtons && (
|
||||
<button
|
||||
className="px-2.5 py-0.5 md:px-3 min-h-[44px] md:min-h-[36px] min-w-0 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer flex-1 md:flex-initial md:w-auto md:max-w-[220px] dark:border-border/30 flex flex-col items-start justify-center overflow-hidden"
|
||||
>
|
||||
<span className="truncate w-full text-left">{displayModelName || 'Select model'}</span>
|
||||
{hasVariants && currentVariant && (
|
||||
<span className="text-[10px] text-highlight truncate w-full text-left capitalize">{currentVariant}</span>
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
className="px-2.5 py-0.5 md:px-3 min-h-[44px] md:min-h-[36px] min-w-0 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer flex-1 md:flex-initial md:w-auto md:max-w-[220px] dark:border-border/30 flex flex-col items-start justify-center overflow-hidden"
|
||||
>
|
||||
<span className="truncate w-full text-left">{displayModelName || 'Select model'}</span>
|
||||
{hasVariants && currentVariant && (
|
||||
<span className="text-[10px] text-highlight truncate w-full text-left capitalize">{currentVariant}</span>
|
||||
)}
|
||||
</button>
|
||||
</ModelQuickSelect>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5 md:gap-2 flex-shrink-0">
|
||||
<div className="flex items-center gap-1.5 md:gap-2 flex-shrink-0">
|
||||
{!isMobile && (
|
||||
<button
|
||||
onClick={onScrollToBottom}
|
||||
@@ -1643,7 +1693,7 @@ return (
|
||||
>
|
||||
<Upload className="w-5 h-5" />
|
||||
</button>
|
||||
{showMobileVoiceButton && (
|
||||
{canUseMobileVoice && (
|
||||
renderVoiceButton('mobile')
|
||||
)}
|
||||
{isMobile && directory && (
|
||||
@@ -1655,63 +1705,15 @@ return (
|
||||
goalLabel={goalButtonLabel}
|
||||
onToggleGoal={toggleGoalArmed}
|
||||
onAttachFile={openFilePicker}
|
||||
onDictate={canUseMobileVoice && hasPromptContent && !showVoiceFeedback ? () => void startVoiceRecording() : undefined}
|
||||
compact={compactControls}
|
||||
/>
|
||||
)}
|
||||
{!isMobile && sttEnabled && sttSupported && (
|
||||
renderVoiceButton('desktop')
|
||||
)}
|
||||
{!showMobileVoiceButton && (
|
||||
<button
|
||||
data-submit-prompt
|
||||
onClick={hasPendingPermissionForSession ? () => setShowDialog(true) : handleSubmit}
|
||||
disabled={hasPendingPermissionForSession ? false : (!isModelReady || !hasPromptContent || (isPromptSubmitPending && !isStreamingResponse))}
|
||||
className={`px-4 md:px-5 py-1.5 md:py-2 rounded-lg text-sm font-medium transition-colors dark:border flex-shrink-0 min-w-[52px] flex items-center justify-center min-h-[44px] md:min-h-0 ${
|
||||
hasPendingPermissionForSession
|
||||
? 'bg-highlight hover:bg-highlight/90 border-highlight text-highlight-foreground ring-highlight/20'
|
||||
: 'bg-primary hover:bg-primary/90 disabled:bg-muted disabled:text-muted-foreground disabled:cursor-not-allowed text-primary-foreground border-border/30'
|
||||
}`}
|
||||
title={hasPendingPermissionForSession ? 'View pending permission' : (isStreamingResponse ? 'Queue message' : 'Send')}
|
||||
>
|
||||
<span className="whitespace-nowrap">{hasPendingPermissionForSession ? 'View' : (isStreamingResponse ? 'Queue' : 'Send')}</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isMobile && isPromptFocused && !hasPendingPermissionForSession && (
|
||||
<div role="toolbar" aria-label="Insert" className="flex items-center gap-1.5 mt-2 pt-2 border-t border-border/50">
|
||||
{KEYBAR_KEYS.map((key) => {
|
||||
const isActive = key.id === 'command'
|
||||
? showSuggestions
|
||||
: key.id === 'mention'
|
||||
? showMentionSuggestions
|
||||
: isBashMode
|
||||
const isDisabled = key.id === 'bash' ? !isBashKeyEnabled : isBashMode
|
||||
return (
|
||||
<button
|
||||
key={key.id}
|
||||
type="button"
|
||||
aria-pressed={isActive}
|
||||
aria-label={`${key.label} ${key.symbol}`}
|
||||
disabled={isDisabled}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onTouchStart={keybarTouch.onTouchStart}
|
||||
onTouchMove={keybarTouch.onTouchMove}
|
||||
onTouchEnd={(e) => keybarTouch.onTouchEnd(e, key.id)}
|
||||
onClick={() => keybarTouch.onClick(key.id)}
|
||||
className={`flex items-center gap-1 min-h-[44px] px-3 rounded-lg border font-mono text-base font-bold transition-colors disabled:opacity-30 ${
|
||||
isActive ? COMPOSER_MODE_STYLES[key.id].key : 'bg-muted border-border text-foreground active:bg-muted-foreground/20'
|
||||
}`}
|
||||
>
|
||||
{key.symbol}
|
||||
<span className="font-sans text-[11px] font-medium opacity-80">{key.label}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<PromptSuggestions
|
||||
isOpen={showSuggestions}
|
||||
items={commandSuggestions}
|
||||
|
||||
Reference in new issue
Block a user