Skip to content

Commit cbb3c8e

Browse files
committed
Like Toggle Data Loading instead of Pending
Using Tailwind clever
1 parent f5dfbda commit cbb3c8e

File tree

4 files changed

+14
-28
lines changed

4 files changed

+14
-28
lines changed

app/Http/Controllers/PuppyController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class PuppyController extends Controller
99
{
1010
public function like(Request $request, Puppy $puppy)
1111
{
12+
sleep(3);
1213
$puppy->likedBy()->toggle($request->user()->id);
1314
return back();
1415
}

resources/js/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ createInertiaApp({
2525
);
2626
},
2727
progress: {
28-
color: '#4B5563',
28+
color: 'var(--color-cyan-500)',
2929
},
3030
});
3131

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { useState } from 'react';
2-
import { Heart, LoaderCircle } from 'lucide-react';
1+
import { like } from '@/routes/puppies';
32
import { Puppy, SharedData } from '@/types';
43
import { Link, usePage } from '@inertiajs/react';
5-
import { like } from '@/routes/puppies';
4+
import { Heart, LoaderCircle } from 'lucide-react';
5+
import { clsx } from 'clsx';
66

77
export function LikeToggle({ puppy }: { puppy: Puppy }) {
8-
const [pending, setPending] = useState(false);
98
const { auth } = usePage<SharedData>().props;
109

1110
return (
@@ -16,17 +15,15 @@ export function LikeToggle({ puppy }: { puppy: Puppy }) {
1615
className={`group ${auth.user ? 'cursor-pointer' : 'cursor-not-allowed'}`}
1716
disabled={!auth?.user}
1817
>
19-
{pending ? (
20-
<LoaderCircle className="animate-spin stroke-slate-300" />
21-
) : (
22-
<Heart
23-
className={
24-
puppy.likedBy.includes(auth?.user?.id) && auth?.user
25-
? 'fill-pink-500 stroke-none'
26-
: 'stroke-slate-200 group-hover:stroke-slate-300'
27-
}
28-
/>
29-
)}
18+
<LoaderCircle className="hidden animate-spin stroke-slate-300 group-data-loading:block" />
19+
<Heart
20+
className={clsx(
21+
puppy.likedBy.includes(auth?.user?.id) && auth?.user
22+
? 'fill-pink-500 stroke-none'
23+
: 'stroke-slate-200 group-hover:stroke-slate-300',
24+
'group-data-loading:hidden',
25+
)}
26+
/>
3027
</Link>
3128
);
3229
}

resources/js/components/Shortlist.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,6 @@ function DeleteButton({ puppy }: { puppy: Puppy }) {
5252
preserveScroll
5353
method={'patch'}
5454
href={like(puppy.id)}
55-
// onClick={async () => {
56-
// setPending(true);
57-
// const updatedPuppy = await toggleLikedStatus(id);
58-
// setPuppies((prevPups) => {
59-
// return prevPups.map((existingPuppy) =>
60-
// existingPuppy.id === updatedPuppy.id
61-
// ? updatedPuppy
62-
// : existingPuppy,
63-
// );
64-
// }); // works if api returns just the updated puppy
65-
// setPending(false);
66-
// }}
6755
className="group h-full border-l border-slate-100 px-2 hover:bg-slate-100"
6856
disabled={pending}
6957
>

0 commit comments

Comments
 (0)