refactor(engine): extract shared getCandidates and getBoxOrigin helpers#69
Open
adrienbrault wants to merge 10 commits into
Open
refactor(engine): extract shared getCandidates and getBoxOrigin helpers#69adrienbrault wants to merge 10 commits into
adrienbrault wants to merge 10 commits into
Conversation
getCandidates was duplicated identically in hint-engine.ts and hint-hidden-single.ts. Moved to sudoku.ts as the canonical implementation and imported in both files. Added getBoxOrigin(coord) to replace the repeated Math.floor(x / 3) * 3 pattern used across 3 files. This makes the box-coordinate calculation explicit and consistent. https://claude.ai/code/session_01CC1b6B5KoC6vieVCSae2Pw
…RD_CELLS Hardcoded 9, 3, and 81 appeared throughout the engine and storage code without semantic meaning. Named constants make the grid structure explicit and provide a single source of truth. https://claude.ai/code/session_01CC1b6B5KoC6vieVCSae2Pw
The clipboard-write → "Copied!" feedback → auto-reset pattern was duplicated in Lobby (twice), FriendsList, and GameResult. Shared hook eliminates the repeated state + setTimeout boilerplate and adds proper timer cleanup on rapid re-clicks. https://claude.ai/code/session_01CC1b6B5KoC6vieVCSae2Pw
useAssistLevel, useNumPadPosition, and useOpponentProgressVisible all repeated the same localStorage init + try/catch + setter boilerplate. Generic useLocalStorage hook with optional type-guard validation eliminates ~15 lines per consumer. useDarkMode is intentionally not migrated — its side effects (class toggling, media query listener) make a generic hook less clear rather than more. https://claude.ai/code/session_01CC1b6B5KoC6vieVCSae2Pw
The 7-level nested ternary for cell background class was hard to read and reason about priority. Early-return function makes the precedence order explicit and each condition independently readable. https://claude.ai/code/session_01CC1b6B5KoC6vieVCSae2Pw
… functions handlePlaceNumber (102 lines) handled three distinct operations: batch note toggle, single note toggle, and number placement. Split into handleBatchNoteToggle, handleSingleNoteToggle, and handleNumberPlacement — each with a single responsibility. handleErase (59 lines) mixed batch and single-cell flows with an inline type definition. Split into handleBatchErase and handleSingleErase with a named ErasedCell type. Also extracted fromCellKey helper to replace the repeated Math.floor(key / 9) / key % 9 pattern, and replaced remaining magic numbers with GRID_SIZE/BOX_SIZE constants. https://claude.ai/code/session_01CC1b6B5KoC6vieVCSae2Pw
…tions The function had two blocks of if/else-if/else branching on group type (row/col/box) — once to collect empty cells, once to collect related filled cells. Extracted getGroupPositions to return all cell positions for any group type uniformly. This eliminates the duplicated branching and reduces findHiddenSingleInGroup from 103 lines to a straightforward filter-and-search flow. https://claude.ai/code/session_01CC1b6B5KoC6vieVCSae2Pw
Board.tsx had ~100 lines of pointer event handling mixed into the rendering component: drag state refs, shift-click logic, click suppression, and getCellFromPoint utility. Moved to a dedicated hook that returns ready-to-spread event handlers, leaving Board focused on rendering. https://claude.ai/code/session_01CC1b6B5KoC6vieVCSae2Pw
Storage key strings were scattered across 12 files with no central registry. Added STORAGE_KEYS object to constants.ts and updated all consumers to reference it. This provides a single place to audit, rename, or search for all persisted keys. https://claude.ai/code/session_01CC1b6B5KoC6vieVCSae2Pw
…focused functions fix formatting in sudokuActions.ts https://claude.ai/code/session_01CC1b6B5KoC6vieVCSae2Pw
11b197e to
178374a
Compare
Deploying sudoku with
|
| Latest commit: |
178374a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://34528932.sudoku-4cc.pages.dev |
| Branch Preview URL: | https://claude-refactor-code-clarity.sudoku-4cc.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getCandidates was duplicated identically in hint-engine.ts and
hint-hidden-single.ts. Moved to sudoku.ts as the canonical
implementation and imported in both files.
Added getBoxOrigin(coord) to replace the repeated
Math.floor(x / 3) * 3 pattern used across 3 files. This makes
the box-coordinate calculation explicit and consistent.
https://claude.ai/code/session_01CC1b6B5KoC6vieVCSae2Pw