Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/AI chat: allow sidebar chats to be deleted
Adorian Doran5ef239da8181
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 2922988f6d..1e5aa34e73 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2101,7 +2101,9 @@"history": "Chat history","recent_chats": "Recent chats","no_chats": "No previous chats",- "view_all_chats": "View all chats"+ "view_all_chats": "View all chats",+ "delete_chat": "Delete chat",+ "delete_confirm": "Delete this chat? This can't be undone."},"shared_switch": {"shared": "Shared",diff --git a/apps/client/src/widgets/sidebar/SidebarChat.css b/apps/client/src/widgets/sidebar/SidebarChat.cssindex d13aa3450c..2c3aadf0c4 100644--- a/apps/client/src/widgets/sidebar/SidebarChat.css+++ b/apps/client/src/widgets/sidebar/SidebarChat.css@@ -66,12 +66,24 @@font-size: 0.85em;}+/* History dropdown row: title/date on the left, delete button pushed to the right. */+.sidebar-chat-history-item.dropdown-item {+ display: flex;+ align-items: center;+ gap: 0.25rem;+}+.sidebar-chat-history-item-content {display: flex;+ flex: 1;flex-direction: column;min-width: 0;}+.sidebar-chat-history-delete {+ flex-shrink: 0;+}+.sidebar-chat-history-item-content span,.sidebar-chat-history-item-content strong {overflow: hidden;diff --git a/apps/client/src/widgets/sidebar/SidebarChat.tsx b/apps/client/src/widgets/sidebar/SidebarChat.tsxindex b634c854f3..dd6f49143d 100644--- a/apps/client/src/widgets/sidebar/SidebarChat.tsx+++ b/apps/client/src/widgets/sidebar/SidebarChat.tsx@@ -6,8 +6,10 @@ import { useCallback, useEffect, useRef, useState } from "preact/hooks";import appContext from "../../components/app_context.js";import dateNoteService, { type RecentLlmChat } from "../../services/date_notes.js";+import dialog from "../../services/dialog.js";import { t } from "../../services/i18n.js";import server from "../../services/server.js";+import { randomString } from "../../services/utils.js";import ws from "../../services/ws.js";import { formatDateTime } from "../../utils/formatters";import ActionButton from "../react/ActionButton.js";@@ -249,6 +251,28 @@ export default function SidebarChat() {}}, [chatNoteId, spacedUpdate]);+ const handleDeleteChat = useCallback(async (noteId: string) => {+ if (!(await dialog.confirm(t("sidebar_chat.delete_confirm")))) return;++ try {+ // Same soft-delete the tree uses (see branches.deleteNotes), minus the delete-notes dialog.+ await server.remove(`notes/${noteId}?taskId=${randomString(10)}&eraseNotes=false&last=true`);+ setRecentChats(prev => prev.filter(c => c.noteId !== noteId));++ // If the open chat was the one deleted, reset the sidebar to a blank state. Don't create a+ // replacement note here — the sidebar lazily creates one on the first message (handleSubmit),+ // so creating one now would leave an empty, timestamp-titled chat cluttering the history.+ // Null the ref too so the clearMessages save below can't write back to the deleted note.+ if (noteId === chatNoteId) {+ setChatNoteId(null);+ chatNoteIdRef.current = null;+ chatRef.current.clearMessages();+ }+ } catch (err) {+ console.error("Failed to delete chat:", err);+ }+ }, [chatNoteId]);+return (<RightPanelWidgetid="sidebar-chat"@@ -281,7 +305,7 @@ export default function SidebarChat() {<FormListItemkey={chatItem.noteId}icon="bx bx-message-square-dots"- className={chatItem.noteId === chatNoteId ? "active" : ""}+ className={`sidebar-chat-history-item ${chatItem.noteId === chatNoteId ? "active" : ""}`}onClick={() => handleSelectChat(chatItem.noteId)}><div className="sidebar-chat-history-item-content">@@ -292,6 +316,15 @@ export default function SidebarChat() {{formatDateTime(new Date(chatItem.dateModified), "short", "short")}</span></div>+ <ActionButton+ icon="bx bx-trash"+ text={t("sidebar_chat.delete_chat")}+ className="sidebar-chat-history-delete"+ onClick={(e) => {+ e.stopPropagation();+ void handleDeleteChat(chatItem.noteId);+ }}+ /></FormListItem>)))}