diff --git a/app/Livewire/DownloadsSearch.php b/app/Livewire/DownloadsSearch.php index 1a54313..b0d08ba 100644 --- a/app/Livewire/DownloadsSearch.php +++ b/app/Livewire/DownloadsSearch.php @@ -5,15 +5,37 @@ namespace App\Livewire; use App\Models\Downloads; use Livewire\Component; use Livewire\WithPagination; +use Livewire\Attributes\Url; class DownloadsSearch extends Component { use WithPagination; + #[Url(history: true)] public $fileSearch; public $order = 'created_at_desc'; + public $options = [ + 'FHD' => true, + 'FHD 48fps' => true, + ]; + + public $isOpen = false; + + // To toggle individual option selection + public function toggleOption($option) + { + $this->options[$option] = !$this->options[$option]; + $this->resetPage(); + } + + // To toggle dropdown visibility + public function toggleDropdown() + { + $this->isOpen = !$this->isOpen; + } + protected $queryString = [ 'fileSearch' => ['except' => '', 'as' => 'fS'], 'order' => ['except' => '', 'as' => 'order'], @@ -24,6 +46,29 @@ class DownloadsSearch extends Component $this->resetPage(); } + // Map the selected options to database types + private function getSelectedTypes() + { + $types = []; + + // Map the options to their corresponding database values + foreach ($this->options as $label => $selected) { + if ($selected) { + if ($label === 'FHD') { + $types[] = 'FHD'; + } elseif ($label === 'FHD 48fps') { + $types[] = 'FHDi'; + } elseif ($label === 'UHD' && auth()->user()->is_patreon) { + $types[] = 'UHD'; + } elseif ($label === 'UHD 48fps' && auth()->user()->is_patreon) { + $types[] = 'UHDi'; + } + } + } + + return $types; + } + public function clicked($downloadId) { $download = Downloads::find($downloadId); @@ -36,6 +81,17 @@ class DownloadsSearch extends Component cache()->forget("episode_{$download->episode->id}_download_{$download->type}"); } + public function mount() + { + if (!auth()->user()->is_patreon) { + return; + } + + // Add patreon options + $this->options['UHD'] = true; + $this->options['UHD 48fps'] = true; + } + public function render() { $orderby = 'created_at'; @@ -72,7 +128,7 @@ class DownloadsSearch extends Component } $downloads = Downloads::when($this->fileSearch != '', fn ($query) => $query->where('url', 'like', '%'.$this->fileSearch.'%')) - ->when(!auth()->user()->is_patreon, fn ($query) => $query->whereIn('type', ['FHD', 'FHDi'])) + ->whereIn('type', $this->getSelectedTypes()) ->whereNotNull('size') ->orderBy($orderby, $orderdirection) ->paginate(20); diff --git a/resources/views/livewire/downloads-search.blade.php b/resources/views/livewire/downloads-search.blade.php index 242b352..95654d6 100644 --- a/resources/views/livewire/downloads-search.blade.php +++ b/resources/views/livewire/downloads-search.blade.php @@ -1,8 +1,8 @@ -