Skip to content

Commit c5d0e8f

Browse files
committed
feat(home): fill textarea on suggested prompt click instead of sending
Clicking a prompt action in the Suggested Actions panel now populates the Mothership user-input textarea (via applyAutoMentions) and focuses it with the caret at end, rather than immediately submitting. The user can review, edit, and send manually.
1 parent 8c86122 commit c5d0e8f

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ export { MothershipChat } from './mothership-chat'
99
export { MothershipView } from './mothership-view'
1010
export { QueuedMessages } from './queued-messages'
1111
export { SuggestedActions } from './suggested-actions'
12-
export { UserInput } from './user-input'
12+
export { UserInput, type UserInputHandle } from './user-input'

apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ interface UserInputProps {
139139

140140
export interface UserInputHandle {
141141
loadQueuedMessage: (msg: QueuedMessage) => void
142+
/** Populates the textarea with `text` (running it through auto-mention
143+
* chipification), focuses the input, and places the caret at the end.
144+
* Does NOT submit. Safe to call with the same text twice in a row. */
145+
populatePrompt: (text: string) => void
142146
}
143147

144148
export const UserInput = forwardRef<UserInputHandle, UserInputProps>(function UserInput(
@@ -459,6 +463,17 @@ export const UserInput = forwardRef<UserInputHandle, UserInputProps>(function Us
459463
textarea.setSelectionRange(end, end)
460464
})
461465
},
466+
populatePrompt: (text: string) => {
467+
const converted = applyAutoMentions(text)
468+
setValue(converted)
469+
requestAnimationFrame(() => {
470+
const textarea = textareaRef.current
471+
if (!textarea) return
472+
textarea.focus()
473+
const end = textarea.value.length
474+
textarea.setSelectionRange(end, end)
475+
})
476+
},
462477
}),
463478
[
464479
files.restoreAttachedFiles,

apps/sim/app/workspace/[workspaceId]/home/home.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
MothershipView,
2929
SuggestedActions,
3030
UserInput,
31+
type UserInputHandle,
3132
} from './components'
3233
import { getMothershipUseChatOptions, useChat, useMothershipResize } from './hooks'
3334
import type { FileAttachmentForApi, MothershipResource, MothershipResourceType } from './types'
@@ -52,6 +53,7 @@ export function Home({ chatId, userName, userId, initialResourceId = null }: Hom
5253
const [initialPrompt, setInitialPrompt] = useState('')
5354
const hasCheckedLandingStorageRef = useRef(false)
5455
const initialViewInputRef = useRef<HTMLDivElement>(null)
56+
const initialViewUserInputRef = useRef<UserInputHandle>(null)
5557

5658
const [isInputEntering, setIsInputEntering] = useState(false)
5759

@@ -312,6 +314,7 @@ export function Home({ chatId, userName, userId, initialResourceId = null }: Hom
312314
</h1>
313315
<div ref={initialViewInputRef} className='w-full'>
314316
<UserInput
317+
ref={initialViewUserInputRef}
315318
defaultValue={initialPrompt}
316319
draftScopeKey={draftScopeKey}
317320
onSubmit={handleSubmit}
@@ -321,7 +324,9 @@ export function Home({ chatId, userName, userId, initialResourceId = null }: Hom
321324
onContextAdd={handleContextAdd}
322325
onContextRemove={handleInitialContextRemove}
323326
/>
324-
<SuggestedActions onSelectPrompt={(prompt) => handleSubmit(prompt)} />
327+
<SuggestedActions
328+
onSelectPrompt={(prompt) => initialViewUserInputRef.current?.populatePrompt(prompt)}
329+
/>
325330
</div>
326331
</div>
327332
</div>

0 commit comments

Comments
 (0)