Skip to content

Commit 863382b

Browse files
committed
feat: add delete history button and improved few ui styling
1 parent b831048 commit 863382b

File tree

2 files changed

+124
-23
lines changed

2 files changed

+124
-23
lines changed

src/pages/aiAssistant/assistant.js

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { isAIMessageChunk } from "@langchain/core/messages";
22
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
33
import { MemorySaver } from "@langchain/langgraph-checkpoint";
44
import { createReactAgent } from "@langchain/langgraph/prebuilt";
5+
import confirm from "dialogs/confirm";
56
import select from "dialogs/select";
67
import he from "he";
78
import Ref from "html-tag-js/ref";
@@ -340,26 +341,51 @@ export default function openAIAssistantPage() {
340341
if (!historyItemsContainer) return;
341342
historyItemsContainer.innerHTML = "";
342343
conversations.forEach((conv) => {
343-
const item = document.createElement("div");
344-
item.className = `history-item ${conv.id === currentConversationId ? "active" : ""}`;
345-
item.onclick = () => {
346-
if (conv.id !== currentConversationId) {
347-
loadOrCreateConversation(conv.id);
348-
toggleHistorySidebar();
349-
}
350-
};
344+
const item = (
345+
<div
346+
className={`history-item ${conv.id === currentConversationId ? "active" : ""}`}
347+
onclick={() => {
348+
if (conv.id !== currentConversationId) {
349+
loadOrCreateConversation(conv.id);
350+
toggleHistorySidebar();
351+
}
352+
}}
353+
/>
354+
);
355+
356+
const iconWrapper = (
357+
<div className="history-icon">
358+
<i
359+
className={`icon ${conv.profile === "write" ? "edit" : "chat_bubble"}`}
360+
></i>
361+
</div>
362+
);
351363

352-
const iconWrapper = document.createElement("div");
353-
iconWrapper.className = "history-icon";
354-
const icon = document.createElement("i");
355-
icon.className = `icon ${conv.profile === "write" ? "edit" : "chat_bubble"}`;
356-
iconWrapper.appendChild(icon);
364+
const text = (
365+
<div className="history-text">{conv.title || "Untitled Chat"}</div>
366+
);
357367

358-
const text = document.createElement("div");
359-
text.className = "history-text";
360-
text.textContent = conv.title || "Untitled Chat";
368+
const deleteBtn = (
369+
<button className="btn btn-icon history-delete" title="Delete chat">
370+
<i className="icon delete"></i>
371+
</button>
372+
);
373+
deleteBtn.onclick = async (e) => {
374+
e.stopPropagation();
375+
const confirmation = await confirm(
376+
"Delete Chat",
377+
`Are you sure you want to delete "<strong>${conv.title || "Untitled Chat"}</strong>"? This action cannot be undone.`,
378+
true,
379+
);
380+
if (!confirmation) return;
381+
await deleteConversation(conv.id);
382+
if (conv.id === currentConversationId) {
383+
await loadOrCreateConversation(null);
384+
}
385+
await updateHistorySidebar();
386+
};
361387

362-
item.append(iconWrapper, text);
388+
item.append(iconWrapper, text, deleteBtn);
363389
historyItemsContainer.appendChild(item);
364390
});
365391
}
@@ -696,9 +722,12 @@ export default function openAIAssistantPage() {
696722
>
697723
<div className="sidebar-header">
698724
<h3 className="sidebar-title">CHAT HISTORY</h3>
699-
<button className="btn btn-icon" title="New Chat from Sidebar">
725+
<button
726+
className="btn btn-icon"
727+
title="New Chat from Sidebar"
728+
onclick={() => loadOrCreateConversation(null)}
729+
>
700730
<i className="icon add"></i>
701-
{/* onclick={() => loadOrCreateConversation(null)} */}
702731
</button>
703732
</div>
704733
<div className="chat-history">

src/pages/aiAssistant/assistant.module.scss

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,24 @@
9292
cursor: pointer;
9393
margin-bottom: 0.25rem;
9494
transition: all 0.2s ease;
95+
position: relative;
9596

9697
&:hover {
9798
background-color: color-mix(
9899
in srgb,
99-
var(--popup-background-color) 20%,
100-
transparent
100+
var(--popup-background-color) 70%,
101+
white
101102
);
102103
}
104+
&:hover .history-delete {
105+
opacity: 1;
106+
}
103107

104108
&.active {
105109
background-color: color-mix(
106110
in srgb,
107-
var(--popup-background-color) 20%,
108-
transparent
111+
var(--popup-background-color) 70%,
112+
white
109113
);
110114
}
111115

@@ -123,6 +127,25 @@
123127
overflow: hidden;
124128
text-overflow: ellipsis;
125129
}
130+
131+
.history-delete {
132+
opacity: 0;
133+
transition: all 0.2s ease;
134+
margin-left: auto;
135+
width: 1.25rem;
136+
height: 1.25rem;
137+
padding: 0;
138+
color: color-mix(
139+
in srgb,
140+
var(--secondary-text-color) 70%,
141+
transparent
142+
);
143+
144+
&:hover {
145+
color: var(--error-text-color);
146+
background-color: rgba(229, 62, 62, 0.1);
147+
}
148+
}
126149
}
127150
}
128151

@@ -138,6 +161,55 @@
138161
width: calc(100% - 240px);
139162
}
140163

164+
.edit-container {
165+
margin-top: 0.75rem;
166+
padding: 0.75rem;
167+
background-color: color-mix(
168+
in srgb,
169+
var(--popup-background-color) 20%,
170+
transparent
171+
);
172+
border-radius: 0.375rem;
173+
border: 1px solid var(--border-color);
174+
}
175+
176+
.edit-textarea {
177+
width: 100%;
178+
min-height: 100px;
179+
padding: 0.75rem;
180+
background-color: var(--primary-color);
181+
border: 1px solid var(--border-color);
182+
border-radius: 0.375rem;
183+
color: var(--primary-text-color);
184+
font-size: 0.875rem;
185+
resize: vertical;
186+
transition: all 0.2s ease;
187+
}
188+
189+
.edit-textarea:focus {
190+
outline: none;
191+
border-color: var(--active-color);
192+
box-shadow: 0 0 0 2px rgba(35, 116, 225, 0.1);
193+
}
194+
195+
.edit-actions {
196+
display: flex;
197+
justify-content: space-between;
198+
align-items: center;
199+
margin-top: 0.75rem;
200+
gap: 0.5rem;
201+
}
202+
203+
.edit-info {
204+
font-size: 0.75rem;
205+
color: color-mix(in srgb, var(--secondary-text-color) 70%, transparent);
206+
}
207+
208+
.edit-buttons {
209+
display: flex;
210+
gap: 0.5rem;
211+
}
212+
141213
.messages-container {
142214
height: 100%;
143215
overflow-y: auto;

0 commit comments

Comments
 (0)