SimpleChat:UI: Helper to create bool button and use it wrt settings

This commit is contained in:
HanishKVC 2024-05-27 00:11:16 +05:30
parent ae7e66d27a
commit e42249d82d
2 changed files with 42 additions and 0 deletions

View file

@ -134,6 +134,7 @@ class SimpleChat {
if (bClear) {
div.innerHTML = gUsageMsg;
gMe.show_info(div);
gMe.show_settings(div);
}
}
}
@ -563,6 +564,24 @@ class Me {
}
/**
* Show settings ui for configurable parameters, in the passed Div element.
* @param {HTMLDivElement} elDiv
*/
show_settings(elDiv) {
let bb = ui.el_create_boolbutton("SetCompletionFreshChatAlways", {true: "[+] CompletionFreshChatAlways", false: "[-] CompletionFreshChatAlways"}, this.bCompletionFreshChatAlways, (val)=>{
this.bCompletionFreshChatAlways = val;
});
elDiv.appendChild(bb);
bb = ui.el_create_boolbutton("SetCompletionInsertStandardRolePrefix", {true: "[+] CompletionInsertStandardRolePrefix", false: "[-] CompletionInsertStandardRolePrefix"}, this.bCompletionInsertStandardRolePrefix, (val)=>{
this.bCompletionInsertStandardRolePrefix = val;
});
elDiv.appendChild(bb);
}
}

View file

@ -60,3 +60,26 @@ export function el_create_append_p(text, elParent=undefined, id=undefined) {
}
return para;
}
/**
* Create a para and set it up. Optionaly append it to a passed parent.
* @param {string} id
* @param {{true: string, false: string}} texts
* @param {boolean} defaultValue
* @param {function(boolean):void} cb
*/
export function el_create_boolbutton(id, texts, defaultValue, cb) {
let el = document.createElement("button");
el["xbool"] = defaultValue;
el["xtexts"] = structuredClone(texts);
el.innerText = el["xtexts"][String(defaultValue)];
if (id) {
el.id = id;
}
el.addEventListener('click', (ev)=>{
el["xbool"] = !el["xbool"];
el.innerText = el["xtexts"][String(el["xbool"])];
cb(el["xbool"]);
})
return el;
}