File tree Expand file tree Collapse file tree 3 files changed +28
-18
lines changed
Expand file tree Collapse file tree 3 files changed +28
-18
lines changed Original file line number Diff line number Diff line change 22
33namespace App \Http \Controllers ;
44
5+ use App \Http \Resources \PuppyResource ;
56use App \Models \Puppy ;
67use Illuminate \Http \Request ;
8+ use Inertia \Inertia ;
9+ use Laravel \Fortify \Features ;
710
811class 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 }
Original file line number Diff line number Diff line change 1- import { Dispatch , SetStateAction , useState } from 'react ' ;
1+ import { like } from '@/routes/puppies ' ;
22import { Puppy , SharedData } from '@/types' ;
3- import { Heart , LoaderCircle , X } from 'lucide-react' ;
43import { 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 ? (
Original file line number Diff line number Diff line change 77use Inertia \Inertia ;
88use 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
1718Route::middleware (['auth ' , 'verified ' ])->group (function () {
1819
You can’t perform that action at this time.
0 commit comments