diff --git a/app/Livewire/Mod/Listing.php b/app/Livewire/Mod/Listing.php index 5f7bc67..7b3e25a 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,6 +33,19 @@ class Listing extends Component #[Url] public string $order = 'created'; + /** + * The number of results to show on a single page. + */ + #[Session] + #[Url] + 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. */ @@ -62,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(); } /** @@ -80,6 +102,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, @@ -87,13 +111,32 @@ class Listing extends Component 'order' => $this->order, 'sptVersions' => $this->sptVersions, ]; - $mods = (new ModFilter($filters))->apply()->paginate(16); + + $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. */ @@ -110,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'; } diff --git a/resources/views/components/filter-menu-item.blade.php b/resources/views/components/filter-menu-item.blade.php new file mode 100644 index 0000000..f355ef0 --- /dev/null +++ b/resources/views/components/filter-menu-item.blade.php @@ -0,0 +1,8 @@ +@props(['filterName', 'filter', 'currentFilter']) + + + {{ $slot }} + diff --git a/resources/views/components/filter-sort-menu-item.blade.php b/resources/views/components/filter-sort-menu-item.blade.php deleted file mode 100644 index c64e207..0000000 --- a/resources/views/components/filter-sort-menu-item.blade.php +++ /dev/null @@ -1,8 +0,0 @@ -@props(['order', 'currentOrder']) - - - {{ $slot }} - diff --git a/resources/views/livewire/mod/listing.blade.php b/resources/views/livewire/mod/listing.blade.php index 10dd0bc..c25c960 100644 --- a/resources/views/livewire/mod/listing.blade.php +++ b/resources/views/livewire/mod/listing.blade.php @@ -99,7 +99,44 @@
-
+
+ {{-- Results Per Page Dropdown --}} +
+
+ {{-- Large display can show full text --}} + + {{-- Only show selected number on smaller screens --}} + +
+ +
+ + {{-- Sort Dropdown --}}
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