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) <noreply@anthropic.com>
This commit is contained in:
thibaud-leclere
2026-04-01 23:10:38 +02:00
parent b637b725d8
commit 51a9f49797
3 changed files with 17 additions and 19 deletions

View File

@@ -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();
});
});
}
}