@@ -4,7 +4,7 @@ import { motion, AnimatePresence } from 'framer-motion';
44import TextareaAutosize from 'react-textarea-autosize' ;
55import { PaperclipIcon , Send , X , Code , Wand2 } from 'lucide-react' ;
66import { cn } from '@/lib/utils' ;
7- import { Message } from '../../const/MessageType' ;
7+ import { Message , ChatRequestOptions } from '../../const/MessageType' ;
88import Image from 'next/image' ;
99import {
1010 Tooltip ,
@@ -19,7 +19,10 @@ interface ChatBottombarProps {
1919 messages : Message [ ] ;
2020 input : string ;
2121 handleInputChange : ( e : React . ChangeEvent < HTMLTextAreaElement > ) => void ;
22- handleSubmit : ( e : React . FormEvent < HTMLFormElement > ) => void ;
22+ handleSubmit : (
23+ e : React . FormEvent < HTMLFormElement > ,
24+ chatRequestOptions ?: ChatRequestOptions
25+ ) => void ;
2326 stop : ( ) => void ;
2427 formRef : React . RefObject < HTMLFormElement > ;
2528 setInput ?: React . Dispatch < React . SetStateAction < string > > ;
@@ -59,6 +62,7 @@ export default function ChatBottombar({
5962 const [ isFocused , setIsFocused ] = useState ( false ) ;
6063 const [ attachments , setAttachments ] = useState < File [ ] > ( [ ] ) ;
6164 const [ isComponentMode , setIsComponentMode ] = useState ( false ) ;
65+ const [ componentData , setComponentData ] = useState < string > ( '' ) ;
6266 const inputRef = useRef < HTMLTextAreaElement > ( null ) ;
6367 const fileInputRef = useRef < HTMLInputElement > ( null ) ;
6468
@@ -98,16 +102,12 @@ export default function ChatBottombar({
98102 setAttachments ( ( prev ) => prev . filter ( ( _ , i ) => i !== index ) ) ;
99103 } ;
100104
101- const submitWithAttachments = ( e : React . FormEvent < HTMLFormElement > ) => {
102- // Here you would normally handle attachments with your form submission
103- // For this example, we'll just clear them after submission
104- handleSubmit ( e ) ;
105- setAttachments ( [ ] ) ;
106- } ;
107-
108105 const populateChatInput = ( content : string ) => {
109106 if ( setInput ) {
110- setInput ( content ) ;
107+ // Store the component data in state instead of showing it in the input
108+ setComponentData ( content ) ;
109+ // Keep input clean - don't prefill any text
110+ setInput ( "" ) ;
111111 setIsComponentMode ( true ) ;
112112 // Focus the input after populating
113113 setTimeout ( ( ) => {
@@ -116,12 +116,11 @@ export default function ChatBottombar({
116116 }
117117 } ;
118118
119- // Check if input still contains component text
119+ // Check if we're still in component mode
120120 useEffect ( ( ) => {
121- if ( input . includes ( 'Help me modify this component:' ) ) {
122- setIsComponentMode ( true ) ;
123- } else {
121+ if ( ! input || input === "" ) {
124122 setIsComponentMode ( false ) ;
123+ setComponentData ( '' ) ;
125124 }
126125 } , [ input ] ) ;
127126
@@ -130,7 +129,41 @@ export default function ChatBottombar({
130129 if ( setInput ) {
131130 setInput ( '' ) ;
132131 setIsComponentMode ( false ) ;
132+ setComponentData ( '' ) ;
133+ }
134+ } ;
135+
136+ // Modify submit to include component data if in component mode
137+ const submitWithAttachments = ( e : React . FormEvent < HTMLFormElement > ) => {
138+ e . preventDefault ( ) ;
139+
140+ // If in component mode, append the hidden component data
141+ if ( isComponentMode && componentData && setInput ) {
142+ // Get user input
143+ const userInput = input || "" ;
144+
145+ // Create the full prompt with component data first, then user input
146+ const fullPrompt = componentData + "\n\n" + userInput ;
147+
148+ // Call handleSubmit with the content in ChatRequestOptions
149+ handleSubmit ( e , { content : fullPrompt } ) ;
150+
151+ // Reset component mode
152+ setIsComponentMode ( false ) ;
153+ setComponentData ( '' ) ;
154+ setAttachments ( [ ] ) ;
155+
156+ // Clean up input after submission
157+ setTimeout ( ( ) => {
158+ setInput ( "" ) ;
159+ } , 50 ) ;
160+
161+ return ;
133162 }
163+
164+ // Regular submission flow
165+ handleSubmit ( e ) ;
166+ setAttachments ( [ ] ) ;
134167 } ;
135168
136169 useEffect ( ( ) => {
@@ -252,8 +285,8 @@ export default function ChatBottombar({
252285 className = "flex items-center gap-1 text-[10px] py-0.5 px-2 bg-purple-50 text-purple-600 border-purple-200 dark:bg-purple-950/60 dark:text-purple-300 dark:border-purple-800/50 shadow-sm"
253286 >
254287 < Wand2 className = "w-2.5 h-2.5" />
255- < span > Component Mode </ span >
256- </ Badge >
288+ < span > Component Selected </ span >
289+ </ Badge >
257290 </ motion . div >
258291 < button
259292 type = "button"
@@ -420,11 +453,8 @@ export default function ChatBottombar({
420453 onFocus = { ( ) => setIsFocused ( true ) }
421454 onBlur = { ( ) => setIsFocused ( false ) }
422455 name = "message"
423- placeholder = { isComponentMode ? "Describe what you want to change..." : "Message Agent..." }
424- className = { cn (
425- "resize-none px-2 w-full focus:outline-none bg-transparent text-gray-800 dark:text-zinc-200 text-sm placeholder:text-gray-400 dark:placeholder:text-zinc-400" ,
426- isComponentMode ? "pt-4 pb-2.5" : "py-2.5"
427- ) }
456+ placeholder = { isComponentMode ? "Message Agent... (component details will be included)" : "Message Agent..." }
457+ className = "resize-none px-2 w-full focus:outline-none bg-transparent text-gray-800 dark:text-zinc-200 text-sm placeholder:text-gray-400 dark:placeholder:text-zinc-400 py-2.5"
428458 maxRows = { 5 }
429459 />
430460 </ div >
0 commit comments