1- import { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
1+ import { useEffect , useMemo , useState } from 'react' ;
22import { CallbackGeneratedChunk , useAppContext } from '../utils/app.context' ;
33import ChatMessage from './ChatMessage' ;
44import { CanvasType , Message , PendingMessage } from '../utils/types' ;
@@ -103,6 +103,10 @@ export default function ChatScreen() {
103103
104104 const textarea : ChatTextareaApi = useChatTextarea ( prefilledMsg . content ( ) ) ;
105105
106+ const { extraContext, clearExtraContext } = useVSCodeContext ( textarea ) ;
107+ // TODO: improve this when we have "upload file" feature
108+ const currExtra : Message [ 'extra' ] = extraContext ? [ extraContext ] : undefined ;
109+
106110 // keep track of leaf node for rendering
107111 const [ currNodeId , setCurrNodeId ] = useState < number > ( - 1 ) ;
108112 const messages : MessageDisplay [ ] = useMemo ( ( ) => {
@@ -128,7 +132,7 @@ export default function ChatScreen() {
128132 scrollToBottom ( true ) ;
129133 } ;
130134
131- const sendNewMessage = useCallback ( async ( ) => {
135+ const sendNewMessage = async ( ) => {
132136 const lastInpMsg = textarea . value ( ) ;
133137 if ( lastInpMsg . trim ( ) . length === 0 || isGenerating ( currConvId ?? '' ) )
134138 return ;
@@ -137,10 +141,6 @@ export default function ChatScreen() {
137141 setCurrNodeId ( - 1 ) ;
138142 // get the last message node
139143 const lastMsgNodeId = messages . at ( - 1 ) ?. msg . id ?? null ;
140- // TODO: improve this when we have "upload file" feature
141- const currExtra = extraContextRef . current
142- ? [ extraContextRef . current ]
143- : undefined ;
144144 if (
145145 ! ( await sendMessage (
146146 currConvId ,
@@ -155,17 +155,10 @@ export default function ChatScreen() {
155155 }
156156 // OK
157157 clearExtraContext ( ) ;
158- } , [ textarea , currConvId , isGenerating , messages , sendMessage , onChunk ] ) ;
159-
160- const { extraContext, clearExtraContext } = useVSCodeContext (
161- textarea ,
162- sendNewMessage
163- ) ;
164- const extraContextRef = useRef ( extraContext ) ;
158+ } ;
165159
166- useEffect ( ( ) => {
167- extraContextRef . current = extraContext ;
168- } , [ extraContext ] ) ;
160+ // for vscode context
161+ textarea . refOnSubmit . current = sendNewMessage ;
169162
170163 const handleEditMessage = async ( msg : Message , content : string ) => {
171164 if ( ! viewingChat ) return ;
0 commit comments