From f3424d3a2a2b37fdcd74ef07b76d6e6ee12bf213 Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Fri, 14 Nov 2025 19:19:57 +0530 Subject: [PATCH] SimpleChatTCRV:Cleanup: Efficient ChatMessage Ui Delete avoid refreshing the full chat session messages ui also Update readme --- tools/server/public_simplechat/readme.md | 3 --- tools/server/public_simplechat/simplechat.js | 23 ++++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tools/server/public_simplechat/readme.md b/tools/server/public_simplechat/readme.md index 96cedbf1bb..194762b49e 100644 --- a/tools/server/public_simplechat/readme.md +++ b/tools/server/public_simplechat/readme.md @@ -779,9 +779,6 @@ same when saved chat is loaded. MAYBE make the settings in general chat session specific, rather than the current global config flow. -Have unique id or use the index into chat messages array wrt each chat message in a chat session, so that -it is easy to identify and remove chat messages from the UI even in sliding window mode. - Have a seperate helper to show the user input area, based on set state. And have support for multiple images if the models support same. diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js index b0397e4042..081af20824 100644 --- a/tools/server/public_simplechat/simplechat.js +++ b/tools/server/public_simplechat/simplechat.js @@ -1346,6 +1346,19 @@ class MultiChatUI { return true } + /** + * Remove the specified ChatMessage block in ui, without needing to show full chat session again. + * @param {number} uniqIdChatMsg + */ + ui_chatmessage_delete(uniqIdChatMsg) { + let index = this.simpleChats[this.curChatId].delete(uniqIdChatMsg) + if (index >= 0) { + let el = document.querySelector(`[CMUniqId="${uniqIdChatMsg}"`) + console.log(el) + el?.remove() + } + } + /** * Setup the needed callbacks wrt UI, curChatId to defaultChatId and * optionally switch to specified defaultChatId. @@ -1442,15 +1455,7 @@ class MultiChatUI { this.elPopoverChatMsgDelBtn.addEventListener('click', (ev) => { console.log(`DBUG:MCUI:ChatMsgPO:Del:${this.curChatId}:${this.uniqIdChatMsgPO}`) - let index = this.simpleChats[this.curChatId].delete(this.uniqIdChatMsgPO) - if (index >= 0) { - this.chat_show(this.curChatId) - let msg = this.simpleChats[this.curChatId].xchat[index] - if (msg) { - let el = document.querySelector(`[CMUniqId="${msg.uniqId}"`) - this.scroll_el_into_view(el) - } - } + this.ui_chatmessage_delete(this.uniqIdChatMsgPO) }) this.elPopoverChatMsgCopyBtn.addEventListener('click', (ev) => {