Skip to content

Commit

Permalink
disable button
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszKielar committed Apr 20, 2024
1 parent 9aca3a2 commit 73918ac
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,19 @@ fn Conversation() -> impl IntoView {
let (messages, set_messages) = create_signal(Vec::<Message>::new());
let (user_prompt, set_user_prompt) = create_signal(String::new());

// set_messages.update(move |messages| {
// let user_msg = Message::user("Why is the sky blue?".to_string(), conversation_id);
// let assistant_msg = Message::assistant("I don't know".to_string(), conversation_id);
// messages.push(user_msg);
// messages.push(assistant_msg);
// });

let send_user_prompt = create_server_action::<AskAssistant>();
let assistant_response_value = send_user_prompt.value();

let (button_disabled, set_button_disabled) = create_signal(true);

create_effect(move |_| {
if user_prompt().len() == 0 || send_user_prompt.pending().get() {
set_button_disabled(true)
} else {
set_button_disabled(false)
};
});

create_effect(move |_| {
if let Some(response) = assistant_response_value.get() {
let assistant_response = response.unwrap();
Expand Down Expand Up @@ -228,6 +231,8 @@ fn Conversation() -> impl IntoView {
set_user_prompt("".to_string());
}
}

disabled=button_disabled
>

<Icon icon=icondata::LuSend class="h-4 w-4 mr-1 text-white "/>
Expand Down

0 comments on commit 73918ac

Please sign in to comment.