refactor(VocabPracticeDialog): replace hard-coded consecutive correct threshold with constant
All checks were successful
Deploy to production / deploy (push) Successful in 1m56s

- Introduced a constant `HARD_REQUIRED_CONSECUTIVE_CORRECT` to define the required number of consecutive correct answers for hard vocabulary items, improving code maintainability and readability.
- Updated relevant methods to utilize the new constant, ensuring consistent behavior across the component.
This commit is contained in:
Torsten Schulz (local)
2026-04-22 11:51:49 +02:00
parent d3aad6e7ef
commit 677e4c674e

View File

@@ -159,6 +159,7 @@ import apiClient from '@/utils/axios.js';
const PRACTICE_MIN_EXPOSURES = 3; const PRACTICE_MIN_EXPOSURES = 3;
const SRS_SESSION_STORAGE_VERSION = 2; const SRS_SESSION_STORAGE_VERSION = 2;
const HARD_REQUIRED_CONSECUTIVE_CORRECT = 5;
export default { export default {
name: 'VocabPracticeDialog', name: 'VocabPracticeDialog',
@@ -303,10 +304,9 @@ export default {
return this.pool.filter((item) => Boolean(this.hardVocabMap[this.getHardKey(item)])); return this.pool.filter((item) => Boolean(this.hardVocabMap[this.getHardKey(item)]));
}, },
hardRemainingCount() { hardRemainingCount() {
const requiredConsecutiveCorrect = 2;
return this.hardPoolItems.filter((item) => { return this.hardPoolItems.filter((item) => {
const key = this.getHardKey(item); const key = this.getHardKey(item);
return (Number(this.hardMasteryByKey[key]) || 0) < requiredConsecutiveCorrect; return (Number(this.hardMasteryByKey[key]) || 0) < HARD_REQUIRED_CONSECUTIVE_CORRECT;
}).length; }).length;
} }
}, },
@@ -782,10 +782,9 @@ export default {
return items.find((it) => it.id === nextId) || null; return items.find((it) => it.id === nextId) || null;
} }
if (this.hardPhaseActive) { if (this.hardPhaseActive) {
const requiredConsecutiveCorrect = 2;
const hardItems = this.hardPoolItems.filter((item) => { const hardItems = this.hardPoolItems.filter((item) => {
const key = this.getHardKey(item); const key = this.getHardKey(item);
return (Number(this.hardMasteryByKey[key]) || 0) < requiredConsecutiveCorrect; return (Number(this.hardMasteryByKey[key]) || 0) < HARD_REQUIRED_CONSECUTIVE_CORRECT;
}); });
if (hardItems.length === 0) { if (hardItems.length === 0) {
this.hardPhaseActive = false; this.hardPhaseActive = false;
@@ -939,7 +938,7 @@ export default {
if (this.hardPhaseActive && this.current) { if (this.hardPhaseActive && this.current) {
const key = this.getHardKey(this.current); const key = this.getHardKey(this.current);
this.hardMasteryByKey[key] = Math.max(0, Number(this.hardMasteryByKey[key]) || 0) + 1; this.hardMasteryByKey[key] = Math.max(0, Number(this.hardMasteryByKey[key]) || 0) + 1;
if ((Number(this.hardMasteryByKey[key]) || 0) >= 2 && this.hardVocabMap[key]) { if ((Number(this.hardMasteryByKey[key]) || 0) >= HARD_REQUIRED_CONSECUTIVE_CORRECT && this.hardVocabMap[key]) {
const next = { ...this.hardVocabMap }; const next = { ...this.hardVocabMap };
delete next[key]; delete next[key];
this.hardVocabMap = next; this.hardVocabMap = next;