CRITICAL FIX: trash buttons now properly update localStorage
- All delete buttons now call loadConversationHistory/saveConversationHistory - Update both localStorage and chat.js module for consistency - User message delete: filters by content match - AI message delete: removes both user and AI messages in pair - Historical message delete: removes by array index - Intro message delete: filters by assistant role and content - No more localStorage sync issues with deleted messages
This commit is contained in:
parent
933ad570ac
commit
401d245fe4
1 changed files with 53 additions and 7 deletions
|
|
@ -1354,13 +1354,18 @@ async function openUncloseaiEmbeddedModalNew() {
|
|||
userDeleteBtn.style.background = colors.actionBg;
|
||||
};
|
||||
userDeleteBtn.onclick = async () => {
|
||||
// Remove from chat history
|
||||
const currentHistory = await getChatHistory();
|
||||
// Remove from chat history and localStorage
|
||||
const { loadConversationHistory, saveConversationHistory } = await import("./storage.js");
|
||||
const { updateChatHistory } = await import("./chat.js");
|
||||
|
||||
const currentHistory = await loadConversationHistory();
|
||||
const updatedHistory = currentHistory.filter(
|
||||
(msg) => !(msg.role === "user" && msg.content === message),
|
||||
);
|
||||
await updateChatHistory(updatedHistory);
|
||||
|
||||
// Update both localStorage and chat.js module
|
||||
await saveConversationHistory(updatedHistory);
|
||||
await updateChatHistory(updatedHistory);
|
||||
|
||||
userMsg.remove();
|
||||
};
|
||||
|
|
@ -1561,7 +1566,23 @@ async function openUncloseaiEmbeddedModalNew() {
|
|||
color: ${colors.primaryText};
|
||||
transition: all 0.2s;
|
||||
`;
|
||||
deleteBtn.onclick = () => {
|
||||
deleteBtn.onclick = async () => {
|
||||
// Remove both user and AI messages from history and localStorage
|
||||
const { loadConversationHistory, saveConversationHistory } = await import("./storage.js");
|
||||
const { updateChatHistory } = await import("./chat.js");
|
||||
|
||||
const currentHistory = await loadConversationHistory();
|
||||
const updatedHistory = currentHistory.filter(
|
||||
(msg) => !(
|
||||
(msg.role === "user" && msg.content === message) ||
|
||||
(msg.role === "assistant" && msg.content === response)
|
||||
)
|
||||
);
|
||||
|
||||
// Update both localStorage and chat.js module
|
||||
await saveConversationHistory(updatedHistory);
|
||||
await updateChatHistory(updatedHistory);
|
||||
|
||||
userMsg.remove();
|
||||
aiMsg.remove();
|
||||
};
|
||||
|
|
@ -2152,9 +2173,21 @@ You have complete knowledge of this page content and can reference any details,
|
|||
font-size: 12px;
|
||||
transition: all 0.2s;
|
||||
`;
|
||||
deleteBtn.onclick = () => {
|
||||
deleteBtn.onclick = async () => {
|
||||
// Remove from chat history and localStorage by index
|
||||
const { loadConversationHistory, saveConversationHistory } = await import("./storage.js");
|
||||
const { updateChatHistory } = await import("./chat.js");
|
||||
|
||||
const currentHistory = await loadConversationHistory();
|
||||
if (index >= 0 && index < currentHistory.length) {
|
||||
currentHistory.splice(index, 1);
|
||||
|
||||
// Update both localStorage and chat.js module
|
||||
await saveConversationHistory(currentHistory);
|
||||
await updateChatHistory(currentHistory);
|
||||
}
|
||||
|
||||
aiMsg.remove();
|
||||
// TODO: Remove from chat history
|
||||
};
|
||||
|
||||
// Copy Raw (Markdown) button
|
||||
|
|
@ -2416,7 +2449,20 @@ You have complete knowledge of this page content and can reference any details,
|
|||
font-size: 12px;
|
||||
transition: all 0.2s;
|
||||
`;
|
||||
deleteBtn.onclick = () => {
|
||||
deleteBtn.onclick = async () => {
|
||||
// Remove intro message from localStorage
|
||||
const { loadConversationHistory, saveConversationHistory } = await import("./storage.js");
|
||||
const { updateChatHistory } = await import("./chat.js");
|
||||
|
||||
const currentHistory = await loadConversationHistory();
|
||||
const updatedHistory = currentHistory.filter(
|
||||
(msg) => !(msg.role === "assistant" && msg.content === response)
|
||||
);
|
||||
|
||||
// Update both localStorage and chat.js module
|
||||
await saveConversationHistory(updatedHistory);
|
||||
await updateChatHistory(updatedHistory);
|
||||
|
||||
introMsg.remove();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue