"combine button components"

This commit is contained in:
yenminh269 2025-10-18 17:44:11 -05:00
commit 3df311634d
8 changed files with 111 additions and 54 deletions

View file

@ -1,6 +1,24 @@
import React from "react";
import ActionButton from "./Button/ActionButton.jsx";
export default function ChatHeader({ title = "AI Assistant" }) {
// Delete chat log (frontend + backend)
const handleDeleteChat = async () => {
if (!window.confirm("Delete all messages?")) return;
await fetch(`/api/chat/${conversationId}`, { method: "DELETE" });
setMessages([]);
};
// Restart chat (new conversation)
const handleNewChat = async () => {
const res = await fetch("/api/chat/new", { method: "POST" });
const data = await res.json();
if (data.success) {
setConversationId(data.conversationId);
setMessages([]);
}
};
return (
<header className="flex items-center justify-between px-4 py-3 bg-gradient-to-r from-slate-800 to-slate-900 text-white">
<div className="flex items-center gap-3">
@ -13,7 +31,10 @@ export default function ChatHeader({ title = "AI Assistant" }) {
Ask anything AI is listening
</p>
</div>
<ActionButton type="add" onClick={handleNewChat}></ActionButton>
<ActionButton type="delete" onClick={handleDeleteChat}></ActionButton>
</div>
</header>
);
}