set up list management
This commit is contained in:
parent
0c42bef077
commit
73d6578857
26 changed files with 495 additions and 230 deletions
11
app/Livewire/Forms/FilterForm.php
Normal file
11
app/Livewire/Forms/FilterForm.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Form;
|
||||
|
||||
class FilterForm extends Form
|
||||
{
|
||||
//
|
||||
}
|
||||
33
app/Livewire/Forms/SettingsForm.php
Normal file
33
app/Livewire/Forms/SettingsForm.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
|
||||
use App\Models\MovieList;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Form;
|
||||
|
||||
class SettingsForm extends Form
|
||||
{
|
||||
#[Locked]
|
||||
public ?int $listId = null;
|
||||
|
||||
public bool $isPublic = false;
|
||||
public string $name = "";
|
||||
|
||||
public function setList(MovieList $list): void
|
||||
{
|
||||
$this->name = $list->name;
|
||||
$this->listId = $list->id;
|
||||
$this->isPublic = $list->is_public;
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
if ($this->listId) {
|
||||
$list = MovieList::find($this->listId);
|
||||
$list->name = $this->name;
|
||||
$list->is_public = $this->isPublic;
|
||||
$list->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
31
app/Livewire/MovieDetailsPanel.php
Normal file
31
app/Livewire/MovieDetailsPanel.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Movie;
|
||||
use Livewire\Component;
|
||||
|
||||
class MovieDetailsPanel extends Component
|
||||
{
|
||||
public $showDetails = false;
|
||||
public ?Movie $selectedMovie = null;
|
||||
|
||||
protected $listeners = ['openMovieDetails' => 'openPanel'];
|
||||
|
||||
public function openPanel(int $movieId): void
|
||||
{
|
||||
$this->selectedMovie = Movie::find($movieId);
|
||||
$this->showDetails = true;
|
||||
}
|
||||
|
||||
public function closePanel(): void
|
||||
{
|
||||
$this->showDetails = false;
|
||||
$this->selectedMovie = null;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.movie-details-panel');
|
||||
}
|
||||
}
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
54
app/Livewire/SearchPanel.php
Normal file
54
app/Livewire/SearchPanel.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Interfaces\MovieDbInterface;
|
||||
use App\Models\Movie;
|
||||
use App\Models\MovieList as MovieListModel;
|
||||
use App\Services\OmdbService;
|
||||
use Livewire\Component;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class SearchPanel extends Component
|
||||
{
|
||||
public $showSearch = false;
|
||||
public $query = '';
|
||||
public $results = [];
|
||||
public int $listId;
|
||||
|
||||
protected $listeners = ['openSearch' => 'openSearchPanel'];
|
||||
|
||||
public function openSearchPanel(): void
|
||||
{
|
||||
$this->showSearch = true;
|
||||
}
|
||||
|
||||
public function findMovies(MovieDbInterface $movie_db): void
|
||||
{
|
||||
try {
|
||||
//$movie = $movie_db->search($this->query, ["type" => "imdb"]);
|
||||
$this->results = $movie_db->search($this->query, ["type" => "title"]);
|
||||
} catch (NotFoundHttpException $e) {
|
||||
$this->addError('query', 'Movie not found');
|
||||
}
|
||||
}
|
||||
|
||||
public function addMovie(MovieDbInterface $movieDb, string $imdbId): void
|
||||
{
|
||||
$this->resetErrorBag();
|
||||
$movie = $movieDb->searchByImdbId($imdbId);
|
||||
|
||||
$list = MovieListModel::find($this->listId);
|
||||
$list->movies()->syncWithoutDetaching($movie->id);
|
||||
|
||||
$this->dispatch('movie-added');
|
||||
$this->showSearch = false;
|
||||
$this->query = '';
|
||||
$this->results = [];
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.search-panel');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue