Refactor IdeationHeader and update handleDeleteSelected logic

- Simplified the IdeationHeader component by removing the Tooltip wrapper around the Delete button for a cleaner UI.
- Updated handleDeleteSelected to fetch the latest selected IDs from the store, ensuring it operates on the current state.
This commit is contained in:
AndyMik90
2025-12-16 23:20:51 +01:00
parent 36a69fcf0d
commit 36338f3546
2 changed files with 15 additions and 18 deletions
@@ -64,20 +64,15 @@ export function IdeationHeader({
<Badge variant="secondary" className="mr-1">
{selectedCount} selected
</Badge>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="outline"
size="sm"
className="text-destructive hover:bg-destructive hover:text-destructive-foreground"
onClick={onDeleteSelected}
>
<Trash2 className="h-4 w-4 mr-1" />
Delete
</Button>
</TooltipTrigger>
<TooltipContent>Delete selected ideas</TooltipContent>
</Tooltip>
<Button
variant="outline"
size="sm"
className="text-destructive hover:bg-destructive hover:text-destructive-foreground"
onClick={onDeleteSelected}
>
<Trash2 className="h-4 w-4 mr-1" />
Delete
</Button>
<Tooltip>
<TooltipTrigger asChild>
<Button
@@ -156,10 +156,12 @@ export function useIdeation(projectId: string, options: UseIdeationOptions = {})
}
};
const handleDeleteSelected = async () => {
if (selectedIds.size === 0) return;
await deleteMultipleIdeasForProject(projectId, Array.from(selectedIds));
};
const handleDeleteSelected = useCallback(async () => {
// Get fresh selectedIds from store to avoid stale closure
const currentSelectedIds = useIdeationStore.getState().selectedIds;
if (currentSelectedIds.size === 0) return;
await deleteMultipleIdeasForProject(projectId, Array.from(currentSelectedIds));
}, [projectId]);
const handleSelectAll = useCallback((ideas: Idea[]) => {
selectAllIdeas(ideas.map(idea => idea.id));