:beers: [Feature] Bind functions with enter to user input
Browse files
apps/llm_mixer/js/buttons_binder.js
CHANGED
@@ -7,34 +7,49 @@ export class ButtonsBinder {
|
|
7 |
bind_send_user_input() {
|
8 |
const button = $("#send-user-input");
|
9 |
button.click(async () => {
|
|
|
|
|
|
|
|
|
10 |
let status = button.text().trim();
|
11 |
-
if (
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
await this.
|
18 |
-
button
|
19 |
-
.text("Regenerate")
|
20 |
-
.removeClass("btn-warning")
|
21 |
-
.addClass("btn-success")
|
22 |
-
.attr("disabled", false);
|
23 |
-
} else if (status === "Stop") {
|
24 |
-
console.log("Stop");
|
25 |
-
this.requester.stop();
|
26 |
-
button
|
27 |
-
.attr("disabled", true)
|
28 |
-
.removeClass("btn-warning")
|
29 |
-
.addClass("btn-success")
|
30 |
-
.text("Regenerate")
|
31 |
-
.attr("disabled", false);
|
32 |
-
return;
|
33 |
-
} else {
|
34 |
-
console.log("No action");
|
35 |
}
|
36 |
});
|
37 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
async post_user_input() {
|
39 |
let user_input = $("#user-input").val();
|
40 |
console.log(user_input);
|
|
|
7 |
bind_send_user_input() {
|
8 |
const button = $("#send-user-input");
|
9 |
button.click(async () => {
|
10 |
+
await this.handle_user_input(button);
|
11 |
+
});
|
12 |
+
|
13 |
+
$("#user-input").keypress(async (event) => {
|
14 |
let status = button.text().trim();
|
15 |
+
if (
|
16 |
+
event.key === "Enter" &&
|
17 |
+
!event.shiftKey &&
|
18 |
+
(status === "Send" || status === "Regenerate")
|
19 |
+
) {
|
20 |
+
event.preventDefault();
|
21 |
+
await this.handle_user_input(button);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
}
|
23 |
});
|
24 |
}
|
25 |
+
async handle_user_input(button) {
|
26 |
+
let status = button.text().trim();
|
27 |
+
if (status === "Send" || status === "Regenerate") {
|
28 |
+
console.log("Send");
|
29 |
+
button
|
30 |
+
.text("Stop")
|
31 |
+
.removeClass("btn-primary btn-success")
|
32 |
+
.addClass("btn-warning");
|
33 |
+
await this.post_user_input();
|
34 |
+
button
|
35 |
+
.text("Regenerate")
|
36 |
+
.removeClass("btn-warning")
|
37 |
+
.addClass("btn-success")
|
38 |
+
.attr("disabled", false);
|
39 |
+
} else if (status === "Stop") {
|
40 |
+
console.log("Stop");
|
41 |
+
this.requester.stop();
|
42 |
+
button
|
43 |
+
.attr("disabled", true)
|
44 |
+
.removeClass("btn-warning")
|
45 |
+
.addClass("btn-success")
|
46 |
+
.text("Regenerate")
|
47 |
+
.attr("disabled", false);
|
48 |
+
return;
|
49 |
+
} else {
|
50 |
+
console.log("No action");
|
51 |
+
}
|
52 |
+
}
|
53 |
async post_user_input() {
|
54 |
let user_input = $("#user-input").val();
|
55 |
console.log(user_input);
|