movie-night-nuevo/app/Livewire/SearchPanel.php

57 lines
1.5 KiB
PHP
Raw Normal View History

2025-12-13 19:33:52 -06:00
<?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 {
2025-12-16 00:19:12 -06:00
logger()->info("finding movies");
2025-12-13 19:33:52 -06:00
//$movie = $movie_db->search($this->query, ["type" => "imdb"]);
$this->results = $movie_db->search($this->query, ["type" => "title"]);
2025-12-16 00:19:12 -06:00
logger()->info($this->results);
2025-12-13 19:33:52 -06:00
} 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');
}
}