diff --git a/assets/controllers/result_filter_controller.js b/assets/controllers/result_filter_controller.js index 3806cdf..a1e5c63 100644 --- a/assets/controllers/result_filter_controller.js +++ b/assets/controllers/result_filter_controller.js @@ -20,6 +20,8 @@ export default class extends Controller { "provider": "", } + userPreferences = [] + static outlets = ['movie-results', 'tv-results'] static targets = ['resolution', 'codec', 'language', 'provider', 'season', 'selectAll', 'downloadSelected'] static values = { @@ -28,22 +30,11 @@ export default class extends Controller { } async connect() { - await fetch('/api/preferences/media') - .then(response => response.json()) - .then(response => { - this.addResolutions(response['resolution']); - this.addCodecs(response['codec']); - }); - - await fetch('/api/user/preferences/values') - .then(response => response.json()) - .then(response => { - this.activeFilter = response; - if (this.mediaTypeValue === "tvshows") { - this.activeFilter['season'] = 1; - } - console.log(this.activeFilter); - }) + this.userPreferences = await(await fetch('/api/user/preferences/values')).json(); + if (this.mediaTypeValue === "tvshows") { + this.activeFilter['season'] = 1; + } + await this.filter(); } async movieResultsOutletConnected(outlet) { @@ -67,14 +58,24 @@ export default class extends Controller { addResolutions(resolutions) { this.resolutionTarget.innerHTML = ''; this.resolutionTarget.innerHTML += resolutions.preferenceOptions - .map((resolution) => '') + .map((resolution) => { + if ('resolution' in this.userPreferences) { + return ''; + } + return ''; + }) .join(); } addCodecs(codecs) { this.codecTarget.innerHTML = ''; this.codecTarget.innerHTML += codecs.preferenceOptions - .map((codec) => '') + .map((codec) => { + if ('codec' in this.userPreferences) { + return ''; + } + return '' + }) .join(); } diff --git a/assets/controllers/tv_results_controller.js b/assets/controllers/tv_results_controller.js index cbce220..805aff2 100644 --- a/assets/controllers/tv_results_controller.js +++ b/assets/controllers/tv_results_controller.js @@ -26,7 +26,8 @@ export default class extends Controller { } async setOptions() { - if (true === this.activeValue) { + if (true === this.activeValue && this.optionsLoaded === false) { + this.optionsLoaded = true; await fetch(`/torrentio/tvshows/${this.tmdbIdValue}/${this.imdbIdValue}/${this.seasonValue}/${this.episodeValue}`) .then(res => res.text()) .then(response => { @@ -38,7 +39,6 @@ export default class extends Controller { } else { this.episodeSelectorTarget.disabled = true; } - this.optionsLoaded = true; this.loadingIconOutlet.increaseCount(); }); } diff --git a/src/Twig/Components/Filter.php b/src/Twig/Components/Filter.php index 0617073..c63de8e 100644 --- a/src/Twig/Components/Filter.php +++ b/src/Twig/Components/Filter.php @@ -2,6 +2,9 @@ namespace App\Twig\Components; +use Aimeos\Map; +use App\User\Framework\Repository\PreferencesRepository; +use Symfony\Bundle\SecurityBundle\Security; use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; use Symfony\UX\LiveComponent\DefaultActionTrait; @@ -9,4 +12,21 @@ use Symfony\UX\LiveComponent\DefaultActionTrait; final class Filter { use DefaultActionTrait; + + public array $preferences = []; + + public array $userPreferences = []; + + public function __construct( + private readonly PreferencesRepository $preferencesRepository, + private readonly Security $security, + ) { + $this->preferences = Map::from($this->preferencesRepository->findEnabled()) + ->rekey(fn($element) => $element->getId()) + ->map(fn($element) => $element->getPreferenceOptions()->toArray()) + ->toArray(); + $this->userPreferences = Map::from($this->security->getUser()->getUserPreferenceValues()) + ->toArray(); +// dd($this->userPreferences); + } } diff --git a/templates/components/Filter.html.twig b/templates/components/Filter.html.twig index 7ec7964..94dccff 100644 --- a/templates/components/Filter.html.twig +++ b/templates/components/Filter.html.twig @@ -13,27 +13,19 @@ class="px-1 py-0.5 bg-stone-100 text-gray-800 rounded-md" value="{{ app.user.userPreferenceValues["resolution"] }}" > -{# #} -{# #} -{# #} -{# #} + + {% for option in this.preferences['resolution'] %} + + {% endfor %}