@@ -745,20 +745,32 @@ impl ChatPanel {
745
745
}
746
746
747
747
fn send_message ( & mut self , cx : & mut Cx , scope : & mut Scope , prompt : String ) {
748
+ // Check if we have any text to send
748
749
if prompt. trim ( ) . is_empty ( ) {
749
750
return ;
750
751
}
751
752
752
- let store = scope. data . get_mut :: < Store > ( ) . unwrap ( ) ;
753
- store. chats . send_chat_message ( prompt. clone ( ) ) ;
753
+ // Let's confirm we're in an appropriate state to send a message
754
+ self . update_state ( scope) ;
755
+ if matches ! (
756
+ self . state,
757
+ State :: ModelSelectedWithChat {
758
+ is_streaming: false ,
759
+ is_loading: false ,
760
+ ..
761
+ } | State :: ModelSelectedWithEmptyChat { is_loading: false }
762
+ ) {
763
+ let store = scope. data . get_mut :: < Store > ( ) . unwrap ( ) ;
764
+ store. chats . send_chat_message ( prompt. clone ( ) ) ;
754
765
755
- let prompt_input = self . text_input ( id ! ( main_prompt_input. prompt) ) ;
756
- prompt_input. set_text_and_redraw ( cx, "" ) ;
757
- prompt_input. set_cursor ( 0 , 0 ) ;
766
+ let prompt_input = self . text_input ( id ! ( main_prompt_input. prompt) ) ;
767
+ prompt_input. set_text_and_redraw ( cx, "" ) ;
768
+ prompt_input. set_cursor ( 0 , 0 ) ;
758
769
759
- // Scroll to the bottom when the message is sent
760
- self . scroll_messages_to_bottom ( cx) ;
761
- self . redraw ( cx) ;
770
+ // Scroll to the bottom when the message is sent
771
+ self . scroll_messages_to_bottom ( cx) ;
772
+ self . redraw ( cx) ;
773
+ }
762
774
}
763
775
764
776
fn update_view ( & mut self , cx : & mut Cx2d , scope : & mut Scope ) {
0 commit comments