From e971684ad8bc3c0859cf6221c8ef1db6518e98c8 Mon Sep 17 00:00:00 2001 From: Benjamin Claassen Date: Fri, 17 Jan 2025 01:20:21 +0100 Subject: [PATCH] Removed invalid class when valid --- reviews/BordedDev/sudoku.rewrite.js | 38 +++++++++++++++++------------ 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/reviews/BordedDev/sudoku.rewrite.js b/reviews/BordedDev/sudoku.rewrite.js index caf5a73..2e49450 100644 --- a/reviews/BordedDev/sudoku.rewrite.js +++ b/reviews/BordedDev/sudoku.rewrite.js @@ -310,6 +310,28 @@ class SudokuHost extends HTMLElement { constructor() { super() + this.#generateKeyProcessors() + } + + syncCellsToSudoku() { + const puzzleGrid = this.#activePuzzle.grid + const baseGrid = this.#activePuzzle.baseState + for (let i = 0; i < SUDOKU_GRID_SIZE; i++) { + this.#cellGrid[i].innerHTML = puzzleGrid[i] ?? "" + + if (baseGrid[i] != null) { + this.#cellGrid[i].classList.add("initial") + } else if (puzzleGrid[i] != null) { + if (this.#activePuzzle.isValueValidForSlot(puzzleGrid[i], i)) { + this.#cellGrid[i].classList.remove("invalid") + } else { + this.#cellGrid[i].classList.add("invalid") + } + } + } + } + + #generateKeyProcessors() { const cellValueProcessor = (event) => { if (this.#selectedCells.size === 0) return @@ -379,22 +401,6 @@ class SudokuHost extends HTMLElement { }) } - syncCellsToSudoku() { - const puzzleGrid = this.#activePuzzle.grid - const baseGrid = this.#activePuzzle.baseState - for (let i = 0; i < SUDOKU_GRID_SIZE; i++) { - this.#cellGrid[i].innerHTML = puzzleGrid[i] ?? "" - - if (baseGrid[i] != null) { - this.#cellGrid[i].classList.add("initial") - } else if (puzzleGrid[i] != null) { - if (!this.#activePuzzle.isValueValidForSlot(puzzleGrid[i], i)) { - this.#cellGrid[i].classList.add("invalid") - } - } - } - } - #selectCell(i, cell) { if (this.hasAttribute("readonly") || !this.isActive) return this.#selectedCells.set(i, cell)