Skip to content

Commit 31c0d60

Browse files
committed
Make sure chat messages can not be sent when no allowed
1 parent 3f0832a commit 31c0d60

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/chat/chat_panel.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -745,20 +745,32 @@ impl ChatPanel {
745745
}
746746

747747
fn send_message(&mut self, cx: &mut Cx, scope: &mut Scope, prompt: String) {
748+
// Check if we have any text to send
748749
if prompt.trim().is_empty() {
749750
return;
750751
}
751752

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());
754765

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);
758769

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+
}
762774
}
763775

764776
fn update_view(&mut self, cx: &mut Cx2d, scope: &mut Scope) {

0 commit comments

Comments
 (0)