From 9244d487138e89754ede56e21e24f4dc4a9aa268 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Fri, 9 Aug 2024 11:19:07 -0400 Subject: [PATCH] wire up search and section filters --- app/Livewire/ModIndex.php | 22 +++++++++++++++++++- resources/views/livewire/mod-index.blade.php | 8 +++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/Livewire/ModIndex.php b/app/Livewire/ModIndex.php index 7b0b660..c629654 100644 --- a/app/Livewire/ModIndex.php +++ b/app/Livewire/ModIndex.php @@ -3,6 +3,7 @@ namespace App\Livewire; use App\Models\Mod; +use Illuminate\Support\Str; use Livewire\Component; use Livewire\WithPagination; @@ -10,15 +11,34 @@ class ModIndex extends Component { use WithPagination; + public $modSearch = ''; + public $sectionFilter = 'new'; public function render() { + // 'new' section is default + $section = 'created_at'; + + switch ($this->sectionFilter) { + case 'most_downloaded': + $section = 'total_downloads'; + break; + case 'recently_updated': + $section = 'updated_at'; + break; + case 'top_rated': + // probably use some kind of 'likes' or something + // not implemented yet afaik -waffle + break; + } + $mods = Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured', 'created_at']) ->withTotalDownloads() ->with(['latestVersion', 'latestVersion.sptVersion', 'users:id,name']) ->whereHas('latestVersion') - ->latest() + ->where('name', 'like', '%'.Str::trim($this->modSearch).'%') //TODO: Is this how search do? Ref please advise. -waffle + ->orderByDesc($section) ->paginate(12); return view('livewire.mod-index', ['mods' => $mods]); diff --git a/resources/views/livewire/mod-index.blade.php b/resources/views/livewire/mod-index.blade.php index 862d0a6..3be079b 100644 --- a/resources/views/livewire/mod-index.blade.php +++ b/resources/views/livewire/mod-index.blade.php @@ -1,9 +1,9 @@
{{-- TODO: - [ ] search bar for mods - [ ] mods section filter - [ ] spt version filter + [X] search bar for mods + [X] spt version filter + - ratings not in yet, otherwise ready [ ] tags filter [ ] small / mobile display handling [ ] light mode theme handling @@ -25,7 +25,7 @@
- +