Skip to content

Commit e9a73e4

Browse files
committed
Make shortlist delete button a Form
1 parent 2296edf commit e9a73e4

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

resources/js/components/Shortlist.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { like } from '@/routes/puppies';
22
import { Puppy, SharedData } from '@/types';
3-
import { Link, usePage } from '@inertiajs/react';
3+
import { Link, useForm, usePage } from '@inertiajs/react';
44
import { Heart, LoaderCircle, X } from 'lucide-react';
55
import { 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+
/*
4270
export 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

Comments
 (0)