From 58426b6e4e4f9728c97afbf2c78b669be998e843 Mon Sep 17 00:00:00 2001 From: w33b Date: Fri, 9 Jan 2026 22:51:15 +0100 Subject: [PATCH] Add studio filter on download page closes #1 --- app/Livewire/DownloadsSearch.php | 17 ++++++++++++++++ .../views/livewire/downloads-search.blade.php | 20 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/Livewire/DownloadsSearch.php b/app/Livewire/DownloadsSearch.php index b0d08ba..dbb9619 100644 --- a/app/Livewire/DownloadsSearch.php +++ b/app/Livewire/DownloadsSearch.php @@ -23,6 +23,10 @@ class DownloadsSearch extends Component public $isOpen = false; + #[Url(history: true)] + public $studios = []; + public $studiosCopy = []; + // To toggle individual option selection public function toggleOption($option) { @@ -46,6 +50,17 @@ class DownloadsSearch extends Component $this->resetPage(); } + public function applyFilters(): void + { + $this->studiosCopy = $this->studios; + $this->resetPage(); + } + + public function revertFilters(): void + { + $this->studios = $this->studiosCopy; + } + // Map the selected options to database types private function getSelectedTypes() { @@ -129,6 +144,7 @@ class DownloadsSearch extends Component $downloads = Downloads::when($this->fileSearch != '', fn ($query) => $query->where('url', 'like', '%'.$this->fileSearch.'%')) ->whereIn('type', $this->getSelectedTypes()) + ->when($this->studios !== [], fn ($q) => $q->whereHas('episode', fn ($query) => $query->whereHas('studio', function ($query) { $query->whereIn('slug', $this->studios); }))) ->whereNotNull('size') ->orderBy($orderby, $orderdirection) ->paginate(20); @@ -136,6 +152,7 @@ class DownloadsSearch extends Component return view('livewire.downloads-search', [ 'downloads' => $downloads, 'query' => $this->fileSearch, + 'studiocount' => is_array($this->studios) ? count($this->studios) : 0, ]); } } diff --git a/resources/views/livewire/downloads-search.blade.php b/resources/views/livewire/downloads-search.blade.php index f787c8a..bfda33a 100644 --- a/resources/views/livewire/downloads-search.blade.php +++ b/resources/views/livewire/downloads-search.blade.php @@ -2,7 +2,7 @@
-
+
@@ -73,6 +73,23 @@ @endif
+ +
+
+
+ +
+

+ @if($studiocount === 0) + Select Studios + @elseif($studiocount === 1) + Selected {{ $studiocount }} Studio + @elseif($studiocount > 1) + Selected {{ $studiocount }} Studios + @endif +

+
+
@@ -247,4 +264,5 @@
{{ $downloads->links('pagination::tailwind') }}
+ @include('modals.filter-studios')