@@ -70,7 +70,6 @@ const scrollToBottom = throttle(
7070 } ,
7171 80
7272) ;
73-
7473export default function ChatScreen ( ) {
7574 const {
7675 viewingChat,
@@ -82,7 +81,9 @@ export default function ChatScreen() {
8281 replaceMessageAndGenerate,
8382 } = useAppContext ( ) ;
8483 const [ inputMsg , setInputMsg ] = useState ( '' ) ;
84+ const [ automaticSend , setAutomaticSend ] = useState ( false ) ;
8585 const inputRef = useRef < HTMLTextAreaElement > ( null ) ;
86+ const { config } = useAppContext ( ) ;
8687
8788 const { extraContext, clearExtraContext } = useVSCodeContext (
8889 inputRef ,
@@ -139,6 +140,40 @@ export default function ChatScreen() {
139140 // OK
140141 clearExtraContext ( ) ;
141142 } ;
143+ useEffect ( ( ) => {
144+ const sendMsg = async ( ) => {
145+ if ( inputMsg . trim ( ) . length === 0 ) return ;
146+ const lastInpMsg = inputMsg ;
147+ setInputMsg ( '' ) ;
148+ scrollToBottom ( false ) ;
149+ setCurrNodeId ( - 1 ) ;
150+ // get the last message node
151+ const lastMsgNodeId = messages . at ( - 1 ) ?. msg . id ?? null ;
152+ if (
153+ ! ( await sendMessage (
154+ currConvId ,
155+ lastMsgNodeId ,
156+ inputMsg ,
157+ undefined ,
158+ onChunk
159+ ) )
160+ ) {
161+ setInputMsg ( lastInpMsg ) ;
162+ }
163+ } ;
164+ if ( automaticSend ) {
165+ setAutomaticSend ( false ) ;
166+ sendMsg ( ) ;
167+ }
168+ } , [
169+ automaticSend ,
170+ clearExtraContext ,
171+ currConvId ,
172+ inputMsg ,
173+ isGenerating ,
174+ messages ,
175+ sendMessage ,
176+ ] ) ;
142177
143178 const handleEditMessage = async ( msg : Message , content : string ) => {
144179 if ( ! viewingChat ) return ;
@@ -202,10 +237,36 @@ export default function ChatScreen() {
202237 >
203238 { /* chat messages */ }
204239 < div id = "messages-list" className = "grow" >
205- < div className = "mt-auto flex justify-center" >
206- { /* placeholder to shift the message to the bottom */ }
207- { viewingChat ? '' : 'Send a message to start' }
208- </ div >
240+ { /* placeholder to shift the message to the bottom */ }
241+ { viewingChat ? (
242+ ''
243+ ) : (
244+ < div className = "flex items-center text-center sm:text-left align-middle h-full mx-auto" >
245+ { config . questionIdeas . length > 0 ? (
246+ < div className = "w-full text-center" >
247+ < div className = "" > Here are some suggestions for you:</ div >
248+ < div className = "grid grid-cols-1 sm:grid-cols-3" >
249+ { [ ...config . questionIdeas ] . map ( ( idea : string , index ) => (
250+ < button
251+ key = { index }
252+ style = { { whiteSpace : 'pre-wrap' } }
253+ className = "btn m-2 sd:m-4 sd:p-2"
254+ onClick = { ( ) => {
255+ setInputMsg ( idea ) ;
256+ setAutomaticSend ( true ) ;
257+ } }
258+ >
259+ { idea }
260+ </ button >
261+ ) ) }
262+ </ div >
263+ < div className = "" > Send a message to start</ div >
264+ </ div >
265+ ) : (
266+ < div className = "" > Send a message to start</ div >
267+ ) }
268+ </ div >
269+ ) }
209270 { [ ...messages , ...pendingMsgDisplay ] . map ( ( msg ) => (
210271 < ChatMessage
211272 key = { msg . msg . id }
0 commit comments