From 4ea50fb0ef76fff502226ce85b2234e663cff561 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Thu, 26 Sep 2024 16:22:27 -0400 Subject: [PATCH 1/5] add initial dropdown still need to handle size constraints --- app/Livewire/Mod/Listing.php | 5 ++- ...m.blade.php => filter-menu-item.blade.php} | 8 ++-- .../views/livewire/mod/listing.blade.php | 39 +++++++++++++++++-- 3 files changed, 43 insertions(+), 9 deletions(-) rename resources/views/components/{filter-sort-menu-item.blade.php => filter-menu-item.blade.php} (57%) diff --git a/app/Livewire/Mod/Listing.php b/app/Livewire/Mod/Listing.php index 422ad0c..eeba87a 100644 --- a/app/Livewire/Mod/Listing.php +++ b/app/Livewire/Mod/Listing.php @@ -29,6 +29,9 @@ class Listing extends Component #[Url] public string $order = 'created'; + #[Url] + public int $resultsPerPage = 12; + /** * The SPT versions filter value. */ @@ -82,7 +85,7 @@ class Listing extends Component 'order' => $this->order, 'sptVersions' => $this->sptVersions, ]; - $mods = (new ModFilter($filters))->apply()->paginate(16); + $mods = (new ModFilter($filters))->apply()->paginate($this->resultsPerPage); $this->redirectOutOfBoundsPage($mods); diff --git a/resources/views/components/filter-sort-menu-item.blade.php b/resources/views/components/filter-menu-item.blade.php similarity index 57% rename from resources/views/components/filter-sort-menu-item.blade.php rename to resources/views/components/filter-menu-item.blade.php index c64e207..b933a8d 100644 --- a/resources/views/components/filter-sort-menu-item.blade.php +++ b/resources/views/components/filter-menu-item.blade.php @@ -1,8 +1,8 @@ -@props(['order', 'currentOrder']) +@props(['filterName', 'filter', 'currentFilter']) - {{ $slot }} diff --git a/resources/views/livewire/mod/listing.blade.php b/resources/views/livewire/mod/listing.blade.php index 10dd0bc..5da9d3b 100644 --- a/resources/views/livewire/mod/listing.blade.php +++ b/resources/views/livewire/mod/listing.blade.php @@ -99,7 +99,38 @@
-
+
+ {{-- Results Per Page Dropdown --}} +
+
+ +
+ +
+ + {{-- Sort Dropdown --}}
From 96a0b82695d21fabd23cf6fb9acd435b550b177b Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Fri, 27 Sep 2024 08:57:11 -0400 Subject: [PATCH 2/5] add small screen control also fix dropdown text colors --- resources/views/components/filter-menu-item.blade.php | 2 +- resources/views/livewire/mod/listing.blade.php | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/resources/views/components/filter-menu-item.blade.php b/resources/views/components/filter-menu-item.blade.php index b933a8d..f355ef0 100644 --- a/resources/views/components/filter-menu-item.blade.php +++ b/resources/views/components/filter-menu-item.blade.php @@ -2,7 +2,7 @@ {{ $slot }} diff --git a/resources/views/livewire/mod/listing.blade.php b/resources/views/livewire/mod/listing.blade.php index 5da9d3b..820b3dc 100644 --- a/resources/views/livewire/mod/listing.blade.php +++ b/resources/views/livewire/mod/listing.blade.php @@ -103,12 +103,20 @@ {{-- Results Per Page Dropdown --}}
- + {{-- Only show selected number on smaller screens --}} +
Date: Mon, 7 Oct 2024 09:53:30 -0600 Subject: [PATCH 3/5] Mod Filter Page - Per Page Option - Validate Value This change validates the input of the per page option so that it has to be one of the provided options. If an option does not match a provided option, it's set to the closest available option. For example, manually setting it to 100000 in the URL param will have it automatically set to the largest option, 50, while manually setting it to 1 will change it to 6, the smallest option. Also made some small language adjustments to get everything to fit a little nicer in the mobile views. --- app/Livewire/Mod/Listing.php | 36 +++++++++++++++++-- .../views/livewire/mod/listing.blade.php | 14 ++++---- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/app/Livewire/Mod/Listing.php b/app/Livewire/Mod/Listing.php index f8ee7de..78942e2 100644 --- a/app/Livewire/Mod/Listing.php +++ b/app/Livewire/Mod/Listing.php @@ -9,6 +9,7 @@ use Illuminate\Contracts\View\View; use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Facades\Cache; use Livewire\Attributes\Computed; +use Livewire\Attributes\Locked; use Livewire\Attributes\Session; use Livewire\Attributes\Url; use Livewire\Component; @@ -32,8 +33,18 @@ class Listing extends Component #[Url] public string $order = 'created'; + /** + * The number of results to show on a single page. + */ + #[Session] #[Url] - public int $resultsPerPage = 12; + public int $perPage = 12; + + /** + * The options that are available for the per page setting. + */ + #[Locked] + public array $perPageOptions = [6, 12, 24, 50]; /** * The SPT versions filter value. @@ -83,6 +94,8 @@ class Listing extends Component */ public function render(): View { + $this->validatePerPage(); + // Fetch the mods using the filters saved to the component properties. $filters = [ 'query' => $this->query, @@ -90,13 +103,32 @@ class Listing extends Component 'order' => $this->order, 'sptVersions' => $this->sptVersions, ]; - $mods = (new ModFilter($filters))->apply()->paginate($this->resultsPerPage); + + $mods = (new ModFilter($filters))->apply()->paginate($this->perPage); $this->redirectOutOfBoundsPage($mods); return view('livewire.mod.listing', compact('mods')); } + /** + * Validate that the option selected is an option that is available by setting it to the closest available version. + */ + public function validatePerPage(): void + { + $this->perPage = collect($this->perPageOptions)->pipe(function ($data) { + $closest = null; + + foreach ($data as $item) { + if ($closest === null || abs($this->perPage - $closest) > abs($item - $this->perPage)) { + $closest = $item; + } + } + + return $closest; + }); + } + /** * Check if the current page is greater than the last page. Redirect if it is. */ diff --git a/resources/views/livewire/mod/listing.blade.php b/resources/views/livewire/mod/listing.blade.php index 820b3dc..c25c960 100644 --- a/resources/views/livewire/mod/listing.blade.php +++ b/resources/views/livewire/mod/listing.blade.php @@ -105,14 +105,14 @@
{{-- Large display can show full text --}} {{-- Only show selected number on smaller screens --}} -
From b895cdc9220347f0c9810652caf68f4309e96575 Mon Sep 17 00:00:00 2001 From: Refringe Date: Mon, 7 Oct 2024 09:54:39 -0600 Subject: [PATCH 4/5] Mod Listing Page - Default Value Method Small refactor to use a method to fetch the default value for SPT Version filters. --- app/Livewire/Mod/Listing.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Livewire/Mod/Listing.php b/app/Livewire/Mod/Listing.php index 78942e2..7b3e25a 100644 --- a/app/Livewire/Mod/Listing.php +++ b/app/Livewire/Mod/Listing.php @@ -76,7 +76,15 @@ class Listing extends Component return SptVersion::getVersionsForLastThreeMinors(); }); - $this->sptVersions = $this->sptVersions ?? $this->getLatestMinorVersions()->pluck('version')->toArray(); + $this->sptVersions = $this->sptVersions ?? $this->getDefaultSptVersions(); + } + + /** + * Get the default values for the SPT Versions filter. + */ + protected function getDefaultSptVersions(): array + { + return $this->getLatestMinorVersions()->pluck('version')->toArray(); } /** @@ -145,7 +153,7 @@ class Listing extends Component public function resetFilters(): void { $this->query = ''; - $this->sptVersions = $this->getLatestMinorVersions()->pluck('version')->toArray(); + $this->sptVersions = $this->getDefaultSptVersions(); $this->featured = 'include'; } From ca472efbbfe71ed6d8d2013d3e83b23c2e6b8c82 Mon Sep 17 00:00:00 2001 From: Refringe Date: Mon, 7 Oct 2024 10:28:13 -0600 Subject: [PATCH 5/5] Profile Detail Page Resolves an issue where the no-mods message didn't show up if the user doesn't have any mods uploaded. Adds some style to the message as well. --- resources/views/user/show.blade.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/resources/views/user/show.blade.php b/resources/views/user/show.blade.php index 5c4a67b..fb29e5a 100644 --- a/resources/views/user/show.blade.php +++ b/resources/views/user/show.blade.php @@ -75,8 +75,8 @@
{{-- Mods --}} -
- @if($mods) +
+ @if($mods->count())
{{ $mods->links() }}
@@ -89,7 +89,9 @@ {{ $mods->links() }}
@else -

{{ __('This user has not yet published any mods.') }}

+

+ {{ __('This user has not yet published any mods.') }} +

@endif