From 7038c4cbf9125f30a2a4871b9ded4e878b74ea7c Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Thu, 21 May 2026 00:08:37 -0700 Subject: [PATCH] fix: prepend newly created agents to top of list instead of appending --- .../features/channels/ui/QuickAddAgentPopover.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/desktop/src/features/channels/ui/QuickAddAgentPopover.tsx b/desktop/src/features/channels/ui/QuickAddAgentPopover.tsx index 958e431294..0b06c3f895 100644 --- a/desktop/src/features/channels/ui/QuickAddAgentPopover.tsx +++ b/desktop/src/features/channels/ui/QuickAddAgentPopover.tsx @@ -237,25 +237,26 @@ export function QuickAddAgentPopover({ const displayItems = React.useMemo(() => { if (!open) return items; const liveMap = new Map(items.map((item) => [getItemKey(item), item])); - // Keep stable order, update each item with live data, add new items at end - const result: QuickAddAgentItem[] = []; + // Keep stable order, update each item with live data + const stable: QuickAddAgentItem[] = []; const seen = new Set(); for (const stableItem of stableItems) { const key = getItemKey(stableItem); const liveItem = liveMap.get(key); if (liveItem) { - result.push(liveItem); + stable.push(liveItem); seen.add(key); } } - // Append any new items that weren't in the snapshot + // Prepend any new items (e.g. newly created agents) at the top + const newItems: QuickAddAgentItem[] = []; for (const item of items) { const key = getItemKey(item); if (!seen.has(key)) { - result.push(item); + newItems.push(item); } } - return result; + return [...newItems, ...stable]; }, [open, stableItems, items]); // Reset state when popover closes