From 23b449ca3f1d356c789812f25036e487440cfb1b Mon Sep 17 00:00:00 2001 From: Zack Schuster Date: Wed, 3 Jul 2024 03:47:45 -0700 Subject: [PATCH] Add toggle to view pawn structure without pieces --- public/pieces/view-pawn-structure.css | 7 ++++++ src/chessground/Chessground.tsx | 2 +- src/components/boards/Board.tsx | 31 +++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 public/pieces/view-pawn-structure.css diff --git a/public/pieces/view-pawn-structure.css b/public/pieces/view-pawn-structure.css new file mode 100644 index 00000000..da1293e3 --- /dev/null +++ b/public/pieces/view-pawn-structure.css @@ -0,0 +1,7 @@ +.bishop, +.knight, +.rook, +.queen, +.king { + display: none; +} diff --git a/src/chessground/Chessground.tsx b/src/chessground/Chessground.tsx index afc965ba..af7411a2 100644 --- a/src/chessground/Chessground.tsx +++ b/src/chessground/Chessground.tsx @@ -18,7 +18,7 @@ export function Chessground( useEffect(() => { if (ref?.current == null) return; if (api) { - api?.set({ + api.set({ ...props, events: { change: () => { diff --git a/src/components/boards/Board.tsx b/src/components/boards/Board.tsx index edf65a84..9ef1a5d0 100644 --- a/src/components/boards/Board.tsx +++ b/src/components/boards/Board.tsx @@ -48,6 +48,8 @@ import { IconEdit, IconEditOff, IconEraser, + IconEye, + IconEyeOff, IconPlus, IconSwitchVertical, IconTarget, @@ -65,6 +67,7 @@ import { chessgroundDests, chessgroundMove } from "chessops/compat"; import { makeSan } from "chessops/san"; import { useAtom, useAtomValue } from "jotai"; import { memo, useContext, useMemo, useState } from "react"; +import { Helmet } from "react-helmet"; import { useHotkeys } from "react-hotkeys-hook"; import { useTranslation } from "react-i18next"; import { match } from "ts-pattern"; @@ -167,8 +170,11 @@ function Board({ if (forcedEP && pos) { dests = forceEnPassant(dests, pos); } - const turn = pos?.turn || "white"; + + const [viewPawnStructure, setViewPawnStructure] = useState(false); const [pendingMove, setPendingMove] = useState(null); + + const turn = pos?.turn || "white"; const orientation = movable === "white" || movable === "black" ? movable @@ -354,6 +360,21 @@ function Board({ )} + + + setViewPawnStructure(!viewPawnStructure)} + > + {viewPawnStructure ? ( + + ) : ( + + )} + + + {saveFile && ( + {viewPawnStructure && ( + + + + )} { + after(orig, dest, metadata) { if (!editingMode) { const from = parseSquare(orig)!; const to = parseSquare(dest)!; @@ -690,6 +716,7 @@ function Board({ enabled: false, }} draggable={{ + enabled: !viewPawnStructure, deleteOnDropOff: editingMode, }} drawable={{