feat : add copy pgn button in analysis and database page

This commit is contained in:
Theprathamshah
2025-04-01 04:02:02 +05:30
committed by GitHub
parent 3ca2ac16bc
commit c4fd94860c
2 changed files with 44 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
import { Grid2 as Grid, IconButton, Tooltip } from "@mui/material";
import { Icon } from "@iconify/react";
import { useAtomValue } from "jotai";
import { boardAtom } from "../states";
import { boardAtom, gameAtom } from "../states";
import { useChessActions } from "@/hooks/useChessActions";
import FlipBoardButton from "./flipBoardButton";
import NextMoveButton from "./nextMoveButton";
@@ -16,7 +16,7 @@ export default function PanelToolBar() {
useChessActions(boardAtom);
const boardHistory = board.history();
const game = useAtomValue(gameAtom);
useEffect(() => {
const onKeyDown = (e: KeyboardEvent) => {
if (boardHistory.length === 0) return;
@@ -65,7 +65,16 @@ export default function PanelToolBar() {
<NextMoveButton />
<GoToLastPositionButton />
<Tooltip title="Copy pgn">
<IconButton
disabled={game.history().length === 0}
onClick={() => {
navigator.clipboard.writeText(game.pgn());
}}
>
<Icon icon="ri:clipboard-line" height={30} />
</IconButton>
</Tooltip>
<SaveButton />
</Grid>
);