set up list management
This commit is contained in:
parent
0c42bef077
commit
73d6578857
26 changed files with 495 additions and 230 deletions
|
|
@ -3,18 +3,25 @@
|
|||
namespace App\Livewire;
|
||||
|
||||
use App\Livewire\Forms\MovieListForm;
|
||||
use App\Models\Interfaces\MovieDbInterface;
|
||||
use App\Livewire\Forms\SettingsForm;
|
||||
use App\Models\MovieList as MovieListModel;
|
||||
use Livewire\Component;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class MovieList extends Component
|
||||
{
|
||||
public int $id;
|
||||
public string $query;
|
||||
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
|
||||
{
|
||||
|
|
@ -30,25 +37,33 @@ class MovieList extends Component
|
|||
if ($list) {
|
||||
$this->list = $list;
|
||||
$this->movies = $list->movies;
|
||||
$this->filteredMovies = $list->movies;
|
||||
$this->settingsForm->setList($list);
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
public function addMovie(MovieDbInterface $movie_db)
|
||||
public function filterMovies(): void
|
||||
{
|
||||
$this->resetErrorBag();
|
||||
$this->filteredMovies = collect($this->movies)
|
||||
->filter(fn($movie) => stripos($movie->title, $this->filterText) !== false);
|
||||
}
|
||||
|
||||
try {
|
||||
$movie = $movie_db->search($this->query);
|
||||
} catch (NotFoundHttpException $e) {
|
||||
$this->addError('query', 'Movie not found');
|
||||
return;
|
||||
}
|
||||
public function toggleSettings(): void
|
||||
{
|
||||
$this->showSettings = !$this->showSettings;
|
||||
}
|
||||
|
||||
$this->list->movies()->syncWithoutDetaching($movie->id);
|
||||
public function saveSettings(): void
|
||||
{
|
||||
$this->settingsForm->save();
|
||||
$this->getList();
|
||||
$this->form->reset();
|
||||
}
|
||||
|
||||
public function updatedSettingsForm(): void
|
||||
{
|
||||
$this->settingsForm->save();
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue