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:
@@ -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();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user