11import { like } from '@/routes/puppies' ;
22import { Puppy , SharedData } from '@/types' ;
3- import { Link , usePage } from '@inertiajs/react' ;
3+ import { Link , useForm , usePage } from '@inertiajs/react' ;
44import { Heart , LoaderCircle , X } from 'lucide-react' ;
55import { useState } from 'react' ;
66
@@ -39,6 +39,34 @@ export function Shortlist({ puppies }: { puppies: Puppy[] }) {
3939 ) ;
4040}
4141
42+ export function DeleteButton ( { puppy } : { puppy : Puppy } ) {
43+ const { auth } = usePage < SharedData > ( ) . props ;
44+ const { processing, patch } = useForm ( ) ;
45+
46+ function submit ( e : React . FormEvent ) {
47+ e . preventDefault ( ) ;
48+ patch ( like ( puppy . id ) . url , { preserveScroll : true } ) ;
49+ }
50+
51+ return (
52+ < form onSubmit = { submit } className = "h-full" >
53+ < button
54+ className = "group h-full cursor-pointer border-l border-slate-100 px-2 hover:bg-slate-100"
55+ type = "submit"
56+ disabled = { ! auth . user || processing }
57+ data-loading = { processing ? true : undefined }
58+ >
59+ { processing ? (
60+ < LoaderCircle className = "size-4 animate-spin stroke-slate-300" />
61+ ) : (
62+ < X className = "size-4 stroke-slate-400 group-hover:stroke-red-400" />
63+ ) }
64+ </ button >
65+ </ form >
66+ ) ;
67+ }
68+
69+ /*
4270export function DeleteButton({ puppy }: { puppy: Puppy }) {
4371 const [pending, setPending] = useState(false);
4472
@@ -61,3 +89,4 @@ export function DeleteButton({ puppy }: { puppy: Puppy }) {
6189 </Link>
6290 );
6391}
92+ */
0 commit comments