mirror of
https://github.com/pacnpal/thrillwiki_laravel.git
synced 2025-12-20 11:11:12 -05:00
Add enums for ReviewStatus, TrackMaterial, LaunchType, RideCategory, and RollerCoasterType; implement Designer and RideModel models; create migrations for ride_models and helpful_votes tables; enhance RideGalleryComponent documentation
This commit is contained in:
101
app/Livewire/RideListComponent.php
Normal file
101
app/Livewire/RideListComponent.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Enums\RideCategory;
|
||||
use App\Models\Ride;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
class RideListComponent extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
/** @var string */
|
||||
public $search = '';
|
||||
|
||||
/** @var string */
|
||||
public $category = '';
|
||||
|
||||
/** @var string */
|
||||
public $sortField = 'name';
|
||||
|
||||
/** @var string */
|
||||
public $sortDirection = 'asc';
|
||||
|
||||
/** @var string */
|
||||
public $viewMode = 'grid';
|
||||
|
||||
/**
|
||||
* Update search term and reset pagination.
|
||||
*/
|
||||
public function updatingSearch(): void
|
||||
{
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update category filter and reset pagination.
|
||||
*/
|
||||
public function updatingCategory(): void
|
||||
{
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort results by the given field.
|
||||
*/
|
||||
public function sortBy(string $field): void
|
||||
{
|
||||
if ($this->sortField === $field) {
|
||||
$this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc';
|
||||
} else {
|
||||
$this->sortDirection = 'asc';
|
||||
}
|
||||
|
||||
$this->sortField = $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle between grid and list views.
|
||||
*/
|
||||
public function toggleView(): void
|
||||
{
|
||||
$this->viewMode = $this->viewMode === 'grid' ? 'list' : 'grid';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available ride categories.
|
||||
*/
|
||||
public function getCategoriesProperty(): array
|
||||
{
|
||||
return RideCategory::options();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filtered and sorted rides query.
|
||||
*/
|
||||
private function getRidesQuery()
|
||||
{
|
||||
return Ride::query()
|
||||
->when($this->search, fn($query, $search) =>
|
||||
$query->where('name', 'like', "%{$search}%")
|
||||
)
|
||||
->when($this->category, fn($query, $category) =>
|
||||
$query->where('category', $category)
|
||||
)
|
||||
->orderBy($this->sortField, $this->sortDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the component.
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$rides = $this->getRidesQuery()->paginate(12);
|
||||
|
||||
return view('livewire.ride-list', [
|
||||
'rides' => $rides,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user