diff --git a/components/DeleteItemButton.tsx b/components/DeleteItemButton.tsx index c41acf1..ffa84fc 100644 --- a/components/DeleteItemButton.tsx +++ b/components/DeleteItemButton.tsx @@ -1,6 +1,6 @@ 'use client' -import { useState } from 'react' +import { useState, useTransition } from 'react' import { useRouter } from 'next/navigation' import { deleteItem } from '@/lib/actions' import { Trash2 } from 'lucide-react' @@ -17,18 +17,25 @@ export default function DeleteItemButton({ itemId, listId, variant = 'full' }: D const { showToast } = useToast() const [isDeleting, setIsDeleting] = useState(false) const [showConfirm, setShowConfirm] = useState(false) + const [isPending, startTransition] = useTransition() const handleDelete = async (e: React.MouseEvent) => { e.preventDefault() e.stopPropagation() setIsDeleting(true) + try { await deleteItem(itemId) showToast('Task deleted successfully', 'success') + + // Reset state immediately setShowConfirm(false) setIsDeleting(false) - // Always refresh to update the UI - router.refresh() + + // Use startTransition to refresh the route + startTransition(() => { + router.refresh() + }) } catch (error) { console.error('Error deleting item:', error) showToast('Failed to delete task', 'error') @@ -54,14 +61,14 @@ export default function DeleteItemButton({ itemId, listId, variant = 'full' }: D