From e6ce29ef15557770c941818e08f9a5945ce3c5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Thu, 26 Sep 2024 17:28:52 +0100 Subject: [PATCH] wip --- app/Http/Controllers/MapController.php | 31 ++++-- app/Providers/AppServiceProvider.php | 2 +- .../js/Components/Map/Filters/Filters.vue | 100 +++++++++--------- .../js/Components/PointDetails/Index.vue | 7 +- resources/js/Components/ReportPoint.vue | 3 +- resources/js/Helpers/checkType.js | 10 ++ resources/js/Helpers/useMap.js | 7 +- resources/js/Pages/{Home.vue => Map.vue} | 2 +- 8 files changed, 99 insertions(+), 63 deletions(-) rename resources/js/Pages/{Home.vue => Map.vue} (91%) diff --git a/app/Http/Controllers/MapController.php b/app/Http/Controllers/MapController.php index 308b997..4b88fe7 100644 --- a/app/Http/Controllers/MapController.php +++ b/app/Http/Controllers/MapController.php @@ -27,13 +27,21 @@ use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Facades\Vite; use Inertia\Inertia; +use Inertia\LazyProp; use Inertia\Response; class MapController extends Controller { - public function index(MapCoordinates $coordinates): Response + public function index(Request $request, MapCoordinates $coordinates): Response { - return $this->render($coordinates); + if ($request->filters()->isEmpty()) { + return $this->render($coordinates); + } + + return $this->render($coordinates, [ + 'context' => 'filter', + 'point' => $this->lazyFetchPoint($request), + ]); } public function point(Point $point, MapCoordinates $coordinates): Response @@ -153,9 +161,7 @@ public function search(Request $request, MapCoordinates $coordinates): Response ->get() ); }, - 'point' => Inertia::lazy(fn () => PointDetailsResource::make( - Point::findOrFail($request->header('Map-Point')) - )), + 'point' => $this->lazyFetchPoint($request), ]); } @@ -165,7 +171,7 @@ protected function render(MapCoordinates $coordinates, array $props = []): Respo ->with('pointTypes') ->get(); - return Inertia::render('Home', [ + return Inertia::render('Map', [ 'mapOptions' => [ 'bounds' => $coordinates->getBoundsBBox(), 'center' => [ @@ -228,4 +234,17 @@ protected function render(MapCoordinates $coordinates, array $props = []): Respo ...$props, ]); } + + protected function lazyFetchPoint(Request $request): LazyProp + { + return Inertia::lazy(function () use ($request) { + if (! $request->hasHeader('Map-Point')) { + return null; + } + + return PointDetailsResource::make( + Point::findOrFail($request->header('Map-Point')) + ); + }); + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 7526a35..862e595 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -109,7 +109,7 @@ protected function registerStrMacros(): void protected function registerRequestMacros(): void { Request::macro('filters', function () { - $filterParts = $this->input('filter', []); + $filterParts = $this->query(); if (\is_string($filterParts)) { return collect(); diff --git a/resources/js/Components/Map/Filters/Filters.vue b/resources/js/Components/Map/Filters/Filters.vue index ea1c46b..c0e4a21 100644 --- a/resources/js/Components/Map/Filters/Filters.vue +++ b/resources/js/Components/Map/Filters/Filters.vue @@ -9,7 +9,7 @@