80 lines
1.8 KiB
PHP
80 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Livewire\Forms\MovieListForm;
|
|
use App\Livewire\Forms\SettingsForm;
|
|
use App\Models\MovieList as MovieListModel;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Component;
|
|
|
|
class MovieList extends Component
|
|
{
|
|
#[locked]
|
|
public int $id;
|
|
public MovieListModel $list;
|
|
public $movies = [];
|
|
public string $filterText = "";
|
|
public $filteredMovies = [];
|
|
public MovieListForm $form;
|
|
public SettingsForm $settingsForm;
|
|
public bool $showSettings = false;
|
|
|
|
protected $listeners = [
|
|
'movie-added' => 'getList',
|
|
'list-updated' => 'getList'
|
|
];
|
|
|
|
public function mount($id): void
|
|
{
|
|
$this->id = $id;
|
|
$this->getList();
|
|
}
|
|
|
|
public function getList()
|
|
{
|
|
$list = MovieListModel::with('movies:id,poster')
|
|
->find($this->id);
|
|
|
|
if ($list) {
|
|
$this->list = $list;
|
|
$this->filteredMovies = $list->movies;
|
|
$this->settingsForm->setList($list);
|
|
} else {
|
|
abort(404);
|
|
}
|
|
}
|
|
|
|
public function deleteList(): void
|
|
{
|
|
$this->list->delete();
|
|
$this->redirectRoute('lists');
|
|
}
|
|
|
|
public function filterMovies(): void
|
|
{
|
|
$this->filteredMovies = collect($this->list->movies)
|
|
->filter(fn($movie) => stripos($movie->title, $this->filterText) !== false);
|
|
}
|
|
|
|
public function toggleSettings(): void
|
|
{
|
|
$this->showSettings = !$this->showSettings;
|
|
}
|
|
|
|
public function saveSettings(): void
|
|
{
|
|
$this->settingsForm->save();
|
|
$this->getList();
|
|
}
|
|
|
|
public function updatedSettingsFormIsPublic(): void
|
|
{
|
|
$this->settingsForm->save();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.movie-list');
|
|
}
|
|
}
|