display filtered spt version

This commit is contained in:
IsWaffle 2024-08-12 11:20:03 -04:00
parent 5dade5dfcf
commit cc3cdddce3
2 changed files with 20 additions and 11 deletions

View File

@ -16,7 +16,7 @@ class ModIndex extends Component
public string $sectionFilter = 'featured'; public string $sectionFilter = 'featured';
public string $versionFilter = ''; public int $versionFilter = -1;
public function render() public function render()
{ {
@ -41,14 +41,23 @@ class ModIndex extends Component
$mods = Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured', 'created_at']) $mods = Mod::select(['id', 'name', 'slug', 'teaser', 'thumbnail', 'featured', 'created_at'])
->withTotalDownloads() ->withTotalDownloads()
->with(['latestVersion', 'latestVersion.sptVersion', 'users:id,name']) ->with(['users:id,name'])
->whereHas('latestVersion') ->where('name', 'like', '%'.Str::trim($this->modSearch).'%');
if ($this->versionFilter === -1) {
$mods = $mods
->with(['latestVersion', 'latestVersion.sptVersion'])
->whereHas('latestVersion.sptVersion');
} else {
$mods = $mods->with(['latestVersion' => function ($query) {
$query->where('spt_version_id', $this->versionFilter);
}, 'latestVersion.sptVersion'])
->whereHas('latestVersion.sptVersion', function ($query) { ->whereHas('latestVersion.sptVersion', function ($query) {
$query->where('version', 'like', '%'.Str::trim($this->versionFilter).'%'); $query->where('spt_version_id', $this->versionFilter);
}) });
->where('name', 'like', '%'.Str::trim($this->modSearch).'%') }
->orderByDesc($section)
->paginate(12); $mods = $mods->orderByDesc($section)->paginate(12);
$sptVersions = SptVersion::select(['id', 'version', 'color_class'])->orderByDesc('version')->get(); $sptVersions = SptVersion::select(['id', 'version', 'color_class'])->orderByDesc('version')->get();

View File

@ -69,9 +69,9 @@
<div class="flex flex-col text-gray-700 bg-gray-300 dark:text-gray-200 dark:bg-gray-950 p-4 rounded-xl"> <div class="flex flex-col text-gray-700 bg-gray-300 dark:text-gray-200 dark:bg-gray-950 p-4 rounded-xl">
<h2>SPT Version</h2> <h2>SPT Version</h2>
<select wire:model.live="versionFilter" class="rounded-md dark:text-white bg-gray-100 dark:bg-gray-950 border-gray-300 dark:border-gray-700 focus:border-grey-500 dark:focus:border-grey-600 focus:ring-grey-500 dark:focus:ring-grey-600"> <select wire:model.live="versionFilter" class="rounded-md dark:text-white bg-gray-100 dark:bg-gray-950 border-gray-300 dark:border-gray-700 focus:border-grey-500 dark:focus:border-grey-600 focus:ring-grey-500 dark:focus:ring-grey-600">
<option disabled value="">Select a version</option> <option disabled value="-1">Select a version</option>
@foreach($sptVersions as $version) @foreach($sptVersions as $version)
<option value="{{ $version->version }}">{{ $version->version }}</option> <option value="{{ $version->id }}">{{ $version->version }}</option>
@endforeach @endforeach
</select> </select>
</div> </div>