29 lines
982 B
TypeScript
29 lines
982 B
TypeScript
"use client";
|
|
import { useTransition } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import { Trash2 } from "lucide-react";
|
|
import { emptyTrash } from "@/app/actions/trash";
|
|
|
|
export function EmptyTrashButton({ count }: { count: number }) {
|
|
const [pending, start] = useTransition();
|
|
const router = useRouter();
|
|
if (count === 0) return null;
|
|
const onClick = () => {
|
|
if (!confirm(`Permanently delete ${count} image${count === 1 ? "" : "s"}? Cannot be undone.`)) return;
|
|
start(async () => {
|
|
await emptyTrash();
|
|
router.refresh();
|
|
});
|
|
};
|
|
return (
|
|
<button
|
|
onClick={onClick}
|
|
disabled={pending}
|
|
className="flex items-center gap-1.5 text-sm px-3 py-1.5 rounded-lg bg-[var(--color-coral)]/15 text-[var(--color-coral)] border border-[var(--color-coral)]/40 hover:bg-[var(--color-coral)]/25 disabled:opacity-50"
|
|
>
|
|
<Trash2 className="w-4 h-4" />
|
|
{pending ? "Emptying…" : "Empty trash"}
|
|
</button>
|
|
);
|
|
}
|