Skip to content

Commit a3c7177

Browse files
committed
Controller Index and Shortlist Delete Spinner
Data Loading set to variable and Start Finish
1 parent cbb3c8e commit a3c7177

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

app/Http/Controllers/PuppyController.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Http\Resources\PuppyResource;
56
use App\Models\Puppy;
67
use Illuminate\Http\Request;
8+
use Inertia\Inertia;
9+
use Laravel\Fortify\Features;
710

811
class PuppyController extends Controller
912
{
13+
public function index()
14+
{
15+
return Inertia::render('welcome', [
16+
'canRegister' => Features::enabled(Features::registration()),
17+
'puppies' => PuppyResource::collection(Puppy::get()->load(['user', 'likedBy'])),
18+
]);
19+
}
20+
1021
public function like(Request $request, Puppy $puppy)
1122
{
12-
sleep(3);
23+
sleep(1);
1324
$puppy->likedBy()->toggle($request->user()->id);
1425
return back();
1526
}

resources/js/components/Shortlist.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import { Dispatch, SetStateAction, useState } from 'react';
1+
import { like } from '@/routes/puppies';
22
import { Puppy, SharedData } from '@/types';
3-
import { Heart, LoaderCircle, X } from 'lucide-react';
43
import { Link, usePage } from '@inertiajs/react';
5-
import { like } from '@/routes/puppies';
4+
import { Heart, LoaderCircle, X } from 'lucide-react';
5+
import { useState } from 'react';
66

7-
export function Shortlist({
8-
puppies,
9-
// setPuppies,
10-
}: {
11-
puppies: Puppy[];
12-
// setPuppies: Dispatch<SetStateAction<Puppy[]>>;
13-
}) {
7+
export function Shortlist({ puppies }: { puppies: Puppy[] }) {
148
const { auth } = usePage<SharedData>().props;
159

1610
return (
@@ -45,14 +39,18 @@ export function Shortlist({
4539
);
4640
}
4741

48-
function DeleteButton({ puppy }: { puppy: Puppy }) {
42+
export function DeleteButton({ puppy }: { puppy: Puppy }) {
4943
const [pending, setPending] = useState(false);
44+
5045
return (
5146
<Link
5247
preserveScroll
5348
method={'patch'}
5449
href={like(puppy.id)}
5550
className="group h-full border-l border-slate-100 px-2 hover:bg-slate-100"
51+
data-loading={pending}
52+
onStart={() => setPending(true)}
53+
onFinish={() => setPending(false)}
5654
disabled={pending}
5755
>
5856
{pending ? (

routes/web.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
use Inertia\Inertia;
88
use Laravel\Fortify\Features;
99

10-
Route::get('/', function () {
11-
return Inertia::render('welcome', [
12-
'canRegister' => Features::enabled(Features::registration()),
13-
'puppies' => PuppyResource::collection(Puppy::get()->load(['user', 'likedBy'])),
14-
]);
15-
})->name('home');
10+
Route::get('/', [PuppyController::class, 'index'])->name('home');
11+
// Route::get('/', function () {
12+
// return Inertia::render('welcome', [
13+
// 'canRegister' => Features::enabled(Features::registration()),
14+
// 'puppies' => PuppyResource::collection(Puppy::get()->load(['user', 'likedBy'])),
15+
// ]);
16+
// })->name('home');
1617

1718
Route::middleware(['auth', 'verified'])->group(function () {
1819

0 commit comments

Comments
 (0)