Something went wrong. Try again.
[heavy wip] dyscalculia/dyslexia friendly version of sudoku (react + rust wasm)
Something went wrong. Try again.
1.2 kB · 45 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546import { useReducer, type ActionDispatch } from "react";import { playingGrid, reduce, type Action, type Initial, type ReductionError,} from "sudoku-rust";
const isReductionError = (val: unknown): val is ReductionError => val === "LockedCell" || (typeof val === "object" && val !== null && "ValidationError" in val && typeof val.ValidationError === "object" && val.ValidationError !== null && "row" in val.ValidationError && "column" in val.ValidationError && "box" in val.ValidationError && typeof val.ValidationError.row === "boolean" && typeof val.ValidationError.column == "boolean" && typeof val.ValidationError.box === "boolean");
export default function useGrid(): [ [Initial, ReductionError | null], ActionDispatch<[Action]>,] { return useReducer( ([{ playing, solution }], action) => { let reduction = reduce(playing, solution, action); if ("Invalid" in reduction) return [{ playing, solution }, reduction.Invalid]; return [ { solution, playing: reduction.Valid, }, null, ]; }, [], // oxlint-disable-next-line (_) => [playingGrid.makeInitial("Medium"), null], );}