set up list management
This commit is contained in:
parent
0c42bef077
commit
73d6578857
26 changed files with 495 additions and 230 deletions
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