SimpleChat:MCUI: Ensure req-resp failure doesnt lock up things

This commit is contained in:
HanishKVC 2024-05-21 18:51:14 +05:30
parent 68ef7401ed
commit 2a407192fc

View file

@ -215,6 +215,18 @@ class MultiChatUI {
}
}
/**
* Reset user input ui.
* * clear user input
* * enable user input
* * set focus to user input
*/
ui_reset_userinput() {
this.elInUser.value = "";
this.elInUser.disabled = false;
this.elInUser.focus();
}
/**
* Setup the needed callbacks wrt UI, curChatId to defaultChatId and
* optionally switch to specified defaultChatId.
@ -232,7 +244,12 @@ class MultiChatUI {
if (this.elInUser.disabled) {
return;
}
this.handle_user_submit(this.curChatId, this.elSelectApiEP.value);
this.handle_user_submit(this.curChatId, this.elSelectApiEP.value).catch((/** @type{Error} */reason)=>{
let msg = `ERRR:MCUI:HandleUserSubmit\n${reason.name}:${reason.message}`;
console.debug(msg.replace("\n", ":"));
alert(msg);
this.ui_reset_userinput();
});
});
this.elInUser.addEventListener("keyup", (ev)=> {
@ -327,9 +344,7 @@ class MultiChatUI {
if ((apiEP == ApiEP.Completion) && (gbCompletionFreshChatAlways)) {
chat.xchat.length = 0;
}
this.elInUser.value = "";
this.elInUser.disabled = false;
this.elInUser.focus();
this.ui_reset_userinput();
}
/**