From 51a9f497976ac4b3d7dc7c73ac5bfd9e3a226f28 Mon Sep 17 00:00:00 2001 From: thibaud-leclere Date: Wed, 1 Apr 2026 23:10:38 +0200 Subject: [PATCH] fix: address code review findings - Guard against empty awardTypeIds array in AwardRepository - Refactor Stimulus controller to use data-action attributes instead of imperative addEventListener (fixes duplicate listener issue) Co-Authored-By: Claude Opus 4.6 (1M context) --- assets/controllers/game_config_controller.js | 24 +++++++------------- src/Repository/AwardRepository.php | 4 ++++ templates/homepage/index.html.twig | 8 ++++--- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/assets/controllers/game_config_controller.js b/assets/controllers/game_config_controller.js index ada75ff..90b3c65 100644 --- a/assets/controllers/game_config_controller.js +++ b/assets/controllers/game_config_controller.js @@ -3,6 +3,14 @@ import { Controller } from '@hotwired/stimulus'; export default class extends Controller { static targets = ['hintType', 'awardSection', 'allAwards', 'awardType']; + enforceMinOneChecked(event) { + const checked = this.hintTypeTargets.filter((e) => e.checked); + if (checked.length === 0) { + event.target.checked = true; + } + this.toggleAwardSection(); + } + toggleAwardSection() { const awardChecked = this.hintTypeTargets.find( (el) => el.name === 'hint_award' @@ -22,20 +30,4 @@ export default class extends Controller { const allChecked = this.awardTypeTargets.every((el) => el.checked); this.allAwardsTarget.checked = allChecked; } - - hintTypeTargetConnected() { - this.#bindMinOneChecked(); - } - - #bindMinOneChecked() { - this.hintTypeTargets.forEach((el) => { - el.addEventListener('change', () => { - const checked = this.hintTypeTargets.filter((e) => e.checked); - if (checked.length === 0) { - el.checked = true; - } - this.toggleAwardSection(); - }); - }); - } } diff --git a/src/Repository/AwardRepository.php b/src/Repository/AwardRepository.php index 252f8a1..ef37e40 100644 --- a/src/Repository/AwardRepository.php +++ b/src/Repository/AwardRepository.php @@ -36,6 +36,10 @@ class AwardRepository extends ServiceEntityRepository ->andWhere('a.actor = :actorId') ->setParameter('actorId', $actorId); + if ($awardTypeIds !== null && empty($awardTypeIds)) { + return null; + } + if ($awardTypeIds !== null) { $qb->andWhere('a.awardType IN (:typeIds)') ->setParameter('typeIds', $awardTypeIds); diff --git a/templates/homepage/index.html.twig b/templates/homepage/index.html.twig index 13c8ace..e992d58 100644 --- a/templates/homepage/index.html.twig +++ b/templates/homepage/index.html.twig @@ -75,18 +75,20 @@