From 2237a45d6f7fedefc74ed71fbad942ffa06a0975 Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Fri, 19 Sep 2025 17:30:57 -0500 Subject: [PATCH] fix: passes latest season to add monitor call --- .../controllers/monitor_button_controller.js | 53 +------------------ .../TmdbTvShowResultDenormalizer.php | 4 ++ src/Tmdb/TmdbResult.php | 1 + templates/search/result.html.twig | 1 + 4 files changed, 8 insertions(+), 51 deletions(-) diff --git a/assets/controllers/monitor_button_controller.js b/assets/controllers/monitor_button_controller.js index f34dcb3..9e1f132 100644 --- a/assets/controllers/monitor_button_controller.js +++ b/assets/controllers/monitor_button_controller.js @@ -13,34 +13,7 @@ export default class extends Controller { tmdbId: String, imdbId: String, title: String, - } - - initialize() { - // Called once when the controller is first instantiated (per element) - - // Here you can initialize variables, create scoped callables for event - // listeners, instantiate external libraries, etc. - // this._fooBar = this.fooBar.bind(this) - } - - connect() { - // Called every time the controller is connected to the DOM - // (on page load, when it's added to the DOM, moved in the DOM, etc.) - - // Here you can add event listeners on the element or target elements, - // add or remove classes, attributes, dispatch custom events, etc. - // this.fooTarget.addEventListener('click', this._fooBar) - } - - // Add custom controller actions here - // fooBar() { this.fooTarget.classList.toggle(this.bazClass) } - - disconnect() { - // Called anytime its element is disconnected from the DOM - // (on page change, when it's removed from or moved in the DOM, etc.) - - // Here you should remove all event listeners added in "connect()" - // this.fooTarget.removeEventListener('click', this._fooBar) + season: Number, } toggle() { @@ -53,34 +26,13 @@ export default class extends Controller { imdbId: this.imdbIdValue, title: this.titleValue, monitorType: 'tvshows', + season: this.seasonValue }); if (this.hasDialogOutlet) { this.dialogOutlet.close(); } } - async monitorSeason() { - await this.makeMonitor({ - tmdbId: this.tmdbIdValue, - imdbId: this.imdbIdValue, - title: this.titleValue, - monitorType: 'tvseason', - season: this.resultFilterOutlet.activeFilter['season'], - }); - } - - async monitorEpisode() { - // ToDo: figure out how to set episode - await this.makeMonitor({ - tmdbId: this.tmdbIdValue, - imdbId: this.imdbIdValue, - title: this.titleValue, - monitorType: 'tvepisode', - season: this.resultFilterOutlet.activeFilter['season'], - episode: '', - }); - } - async makeMonitor(body) { const response = await fetch('/api/monitor', { method: 'POST', @@ -90,7 +42,6 @@ export default class extends Controller { }, body: JSON.stringify(body) }); - return await response.json(); } } diff --git a/src/Tmdb/Framework/Serializer/TmdbTvShowResultDenormalizer.php b/src/Tmdb/Framework/Serializer/TmdbTvShowResultDenormalizer.php index 0323dcc..b3fd9f4 100644 --- a/src/Tmdb/Framework/Serializer/TmdbTvShowResultDenormalizer.php +++ b/src/Tmdb/Framework/Serializer/TmdbTvShowResultDenormalizer.php @@ -38,6 +38,10 @@ class TmdbTvShowResultDenormalizer extends TmdbResultDenormalizer implements Den $result->year = (null !== $airDate) ? $airDate->format('Y') : null; $result->mediaType = MediaType::TvShow->value; + if (is_array($result->episodes)) { + $result->latestSeason = array_key_last($result->episodes); + } + return $result; } diff --git a/src/Tmdb/TmdbResult.php b/src/Tmdb/TmdbResult.php index 6a8fe38..198fc63 100644 --- a/src/Tmdb/TmdbResult.php +++ b/src/Tmdb/TmdbResult.php @@ -56,5 +56,6 @@ class TmdbResult public ?array $producers = null, public ?int $runtime = null, public ?int $numberSeasons = null, + public ?int $latestSeason = null, ) {} } diff --git a/templates/search/result.html.twig b/templates/search/result.html.twig index f3af84b..e54888e 100644 --- a/templates/search/result.html.twig +++ b/templates/search/result.html.twig @@ -28,6 +28,7 @@ tmdbId: results.media.tmdbId, imdbId: results.media.imdbId, title: results.media.title, + season: results.media.latestSeason, })}} data-monitor-button-result-filter-outlet="#filter" data-monitor-button-dialog-outlet=".monitor-modal"