Toast notifications for memory mutations, slide-in animation
This commit is contained in:
+20
-3
@@ -4,6 +4,7 @@ import { useState } from "react";
|
||||
import { Plus } from "lucide-react";
|
||||
import { useMemory, useAddMemory, usePatchMemory, useDeleteMemory } from "@/lib/hooks";
|
||||
import { MemoryEntry } from "@/components/MemoryEntry";
|
||||
import { useToast } from "@/components/Toast";
|
||||
|
||||
const TABS = [
|
||||
{ id: "memory", label: "Agent" },
|
||||
@@ -18,6 +19,7 @@ export default function MemoryPage() {
|
||||
const addMutation = useAddMemory();
|
||||
const patchMutation = usePatchMemory();
|
||||
const deleteMutation = useDeleteMemory();
|
||||
const { toast } = useToast();
|
||||
|
||||
const target = data?.targets?.find((t) => t.target === tab);
|
||||
const entries = target?.entries || [];
|
||||
@@ -28,7 +30,22 @@ export default function MemoryPage() {
|
||||
const handleAdd = () => {
|
||||
if (!newText.trim()) return;
|
||||
addMutation.mutate({ target: tab, content: newText.trim() }, {
|
||||
onSuccess: () => { setNewText(""); setAdding(false); },
|
||||
onSuccess: () => { setNewText(""); setAdding(false); toast("Entry added"); },
|
||||
onError: () => toast("Failed to add entry", "error"),
|
||||
});
|
||||
};
|
||||
|
||||
const handlePatch = (oldText: string, newContent: string) => {
|
||||
patchMutation.mutate({ target: tab, old_text: oldText, content: newContent }, {
|
||||
onSuccess: () => toast("Entry updated"),
|
||||
onError: () => toast("Failed to update", "error"),
|
||||
});
|
||||
};
|
||||
|
||||
const handleDelete = (oldText: string) => {
|
||||
deleteMutation.mutate({ target: tab, old_text: oldText }, {
|
||||
onSuccess: () => toast("Entry deleted"),
|
||||
onError: () => toast("Failed to delete", "error"),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -115,8 +132,8 @@ export default function MemoryPage() {
|
||||
<MemoryEntry
|
||||
key={tab + "-" + i}
|
||||
content={entry}
|
||||
onPatch={(nc) => patchMutation.mutate({ target: tab, old_text: entry.slice(0, 40), content: nc })}
|
||||
onDelete={() => deleteMutation.mutate({ target: tab, old_text: entry.slice(0, 40) })}
|
||||
onPatch={(nc) => handlePatch(entry.slice(0, 40), nc)}
|
||||
onDelete={() => handleDelete(entry.slice(0, 40))}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user