|
@@ -50,15 +50,6 @@ function hasPartialRow(board: CellState[][]): boolean {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function isEmpty(board: CellState[][]): boolean {
|
|
|
|
|
- for (const row of board) {
|
|
|
|
|
- for (const cell of row) {
|
|
|
|
|
- if (cell.letter !== '') return false;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return true;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
export function SolverBoard({ onUpdate, loading }: SolverBoardProps) {
|
|
export function SolverBoard({ onUpdate, loading }: SolverBoardProps) {
|
|
|
const [board, setBoard] = useState<CellState[][]>(emptyBoard);
|
|
const [board, setBoard] = useState<CellState[][]>(emptyBoard);
|
|
|
const [cursor, setCursor] = useState<{ row: number; col: number }>({ row: 0, col: 0 });
|
|
const [cursor, setCursor] = useState<{ row: number; col: number }>({ row: 0, col: 0 });
|
|
@@ -72,13 +63,12 @@ export function SolverBoard({ onUpdate, loading }: SolverBoardProps) {
|
|
|
loadingRef.current = loading;
|
|
loadingRef.current = loading;
|
|
|
|
|
|
|
|
const partial = hasPartialRow(board);
|
|
const partial = hasPartialRow(board);
|
|
|
- const empty = isEmpty(board);
|
|
|
|
|
- const updateDisabled = loading || empty || partial;
|
|
|
|
|
|
|
+ const updateDisabled = loading || partial;
|
|
|
|
|
|
|
|
const triggerUpdate = useCallback(() => {
|
|
const triggerUpdate = useCallback(() => {
|
|
|
const b = boardRef.current;
|
|
const b = boardRef.current;
|
|
|
const r = buildRows(b);
|
|
const r = buildRows(b);
|
|
|
- if (isEmpty(b) || hasPartialRow(b) || loadingRef.current) return;
|
|
|
|
|
|
|
+ if (hasPartialRow(b) || loadingRef.current) return;
|
|
|
onUpdate(r);
|
|
onUpdate(r);
|
|
|
}, [onUpdate]);
|
|
}, [onUpdate]);
|
|
|
|
|
|