Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggle to view pawn structure without pieces #323

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions public/pieces/view-pawn-structure.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.bishop,
.knight,
.rook,
.queen,
.king {
display: none;
}
2 changes: 1 addition & 1 deletion src/chessground/Chessground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function Chessground(
useEffect(() => {
if (ref?.current == null) return;
if (api) {
api?.set({
api.set({
...props,
events: {
change: () => {
Expand Down
31 changes: 29 additions & 2 deletions src/components/boards/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import {
import { notifications } from "@mantine/notifications";
import {
IconArrowBack,
IconChess,
IconChessFilled,
IconChevronRight,
IconDeviceFloppy,
IconEdit,
Expand All @@ -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";
Expand Down Expand Up @@ -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<NormalMove | null>(null);

const turn = pos?.turn || "white";
const orientation =
movable === "white" || movable === "black"
? movable
Expand Down Expand Up @@ -354,6 +360,21 @@ function Board({
</ActionIcon>
</Tooltip>
)}

<Tooltip label="Toggle Pawn Structure View">
<ActionIcon
variant={editingMode ? "filled" : "default"}
size="lg"
onClick={() => setViewPawnStructure(!viewPawnStructure)}
>
{viewPawnStructure ? (
<IconChessFilled size="1.3rem" />
) : (
<IconChess size="1.3rem" />
)}
</ActionIcon>
</Tooltip>

{saveFile && (
<Tooltip label={`Save PGN (${keyMap.SAVE_FILE.keys})`}>
<ActionIcon
Expand Down Expand Up @@ -518,6 +539,11 @@ function Board({

return (
<>
{viewPawnStructure && (
<Helmet>
<link rel="stylesheet" href="/pieces/view-pawn-structure.css" />
</Helmet>
)}
<Box w="100%" h="100%">
<Box
style={{
Expand Down Expand Up @@ -649,7 +675,7 @@ function Board({
: dests,
showDests,
events: {
after: (orig, dest, metadata) => {
after(orig, dest, metadata) {
if (!editingMode) {
const from = parseSquare(orig)!;
const to = parseSquare(dest)!;
Expand Down Expand Up @@ -690,6 +716,7 @@ function Board({
enabled: false,
}}
draggable={{
enabled: !viewPawnStructure,
deleteOnDropOff: editingMode,
}}
drawable={{
Expand Down
Loading