From f6102972941b164fc79e1a83672726e86fa96330 Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Mon, 14 Jul 2025 20:54:12 -0500 Subject: [PATCH] fix: turbo frame for tvshow results --- assets/controllers/tv_results_controller.js | 44 ++++++------------- .../Framework/Controller/WebController.php | 15 ++++--- templates/components/TvEpisodeList.html.twig | 11 ++++- templates/torrentio/fragments.html.twig | 8 ++++ 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/assets/controllers/tv_results_controller.js b/assets/controllers/tv_results_controller.js index bbf1e90..6fce56e 100644 --- a/assets/controllers/tv_results_controller.js +++ b/assets/controllers/tv_results_controller.js @@ -25,37 +25,18 @@ export default class extends Controller { optionsLoaded = false isOpen = false - async connect() { - await this.setOptions(); - } - - async setOptions() { - if (this.optionsLoaded === false) { - this.optionsLoaded = true; - let response; - - try { - response = await fetch(`/torrentio/tvshows/${this.tmdbIdValue}/${this.imdbIdValue}/${this.seasonValue}/${this.episodeValue}`) - } catch (error) { - console.log('There was an error', error); - } - - if (response?.ok) { - response = await response.text() - this.listContainerTarget.innerHTML = response; - this.options = this.element.querySelectorAll('tbody tr'); - if (this.options.length > 0) { - this.options.forEach((option) => option.querySelector('.download-btn').dataset['title'] = this.titleValue); - this.options[0].querySelector('input[type="checkbox"]').checked = true; - } else { - this.countTarget.innerText = 0; - this.episodeSelectorTarget.disabled = true; - } - this.dispatch('optionsLoaded', {detail: {options: this.options}}) - this.loadingIconOutlet.increaseCount(); - } else { - console.log(`HTTP Response Code: ${response?.status}`) - } + async listTargetConnected() { + this.options = this.element.querySelectorAll('tbody tr'); + if (this.options.length > 0) { + this.options.forEach((option) => + option.querySelector('.download-btn').dataset['title'] = this.titleValue + ); + this.options[0].querySelector('input[type="checkbox"]').checked = true; + this.dispatch('optionsLoaded', {detail: {options: this.options}}) + this.loadingIconOutlet.increaseCount(); + } else { + this.countTarget.innerText = 0; + this.episodeSelectorTarget.disabled = true; } } @@ -134,6 +115,7 @@ export default class extends Controller { "codec": option.querySelector('#codec').textContent.trim(), "provider": option.querySelector('#provider').textContent.trim(), "languages": JSON.parse(option.dataset['languages']), + "quality": option.dataset['quality'], } let include = true; diff --git a/src/Torrentio/Framework/Controller/WebController.php b/src/Torrentio/Framework/Controller/WebController.php index 518e9cf..20d31f6 100644 --- a/src/Torrentio/Framework/Controller/WebController.php +++ b/src/Torrentio/Framework/Controller/WebController.php @@ -35,8 +35,8 @@ final class WebController extends AbstractController $input->imdbId ); - // return $cache->get($cacheId, function (ItemInterface $item) use ($input, $request) { - // $item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0)); + return $cache->get($cacheId, function (ItemInterface $item) use ($input, $request) { + $item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0)); $results = $this->getMovieOptionsHandler->handle($input->toCommand()); if ($request->headers->get('Turbo-Frame')) { @@ -46,11 +46,11 @@ final class WebController extends AbstractController return $this->render('torrentio/movies.html.twig', [ 'results' => $results, ]); - //}); + }); } #[Route('/torrentio/tvshows/{tmdbId}/{imdbId}/{season?}/{episode?}', name: 'app_torrentio_tvshows')] - public function tvShowOptions(GetTvShowOptionsInput $input, CacheInterface $cache): Response + public function tvShowOptions(GetTvShowOptionsInput $input, CacheInterface $cache, Request $request): Response { $cacheId = sprintf( "page.torrentio.tvshows.%s.%s.%s.%s", @@ -61,9 +61,14 @@ final class WebController extends AbstractController ); try { -// return $cache->get($cacheId, function (ItemInterface $item) use ($input) { +// return $cache->get($cacheId, function (ItemInterface $item) use ($input, $request) { // $item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0)); $results = $this->getTvShowOptionsHandler->handle($input->toCommand()); + + if ($request->headers->get('Turbo-Frame')) { + return $this->sendFragmentResponse($results, $request); + } + return $this->render('torrentio/tvshows.html.twig', [ 'results' => $results, ]); diff --git a/templates/components/TvEpisodeList.html.twig b/templates/components/TvEpisodeList.html.twig index 7d1a800..002a4e7 100644 --- a/templates/components/TvEpisodeList.html.twig +++ b/templates/components/TvEpisodeList.html.twig @@ -74,8 +74,15 @@ -
- +
+
diff --git a/templates/torrentio/fragments.html.twig b/templates/torrentio/fragments.html.twig index a129cf8..e4b221e 100644 --- a/templates/torrentio/fragments.html.twig +++ b/templates/torrentio/fragments.html.twig @@ -8,4 +8,12 @@ +{% endblock %} + +{% block tvshow_results %} + + + {% endblock %} \ No newline at end of file