fix: prepend newly created agents to top of list instead of appending

This commit is contained in:
Taylor Ho
2026-05-21 00:08:37 -07:00
parent abdb683638
commit 7038c4cbf9

View File

@@ -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<string>();
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