From 46a29645e23ca3ee393d29f24acd23ce8612a4da Mon Sep 17 00:00:00 2001 From: GuillaumeSD Date: Mon, 9 Jun 2025 03:00:48 +0200 Subject: [PATCH] fix : hotkey to flip the board --- .../analysis/panelToolbar/flipBoardButton.tsx | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/sections/analysis/panelToolbar/flipBoardButton.tsx b/src/sections/analysis/panelToolbar/flipBoardButton.tsx index e69c77e..dbd6e6d 100644 --- a/src/sections/analysis/panelToolbar/flipBoardButton.tsx +++ b/src/sections/analysis/panelToolbar/flipBoardButton.tsx @@ -2,24 +2,25 @@ import { useSetAtom } from "jotai"; import { boardOrientationAtom } from "../states"; import { IconButton, Tooltip } from "@mui/material"; import { Icon } from "@iconify/react"; +import { useEffect } from "react"; export default function FlipBoardButton() { const setBoardOrientation = useSetAtom(boardOrientationAtom); - useEffect(() => { - const onKeyDown = (e: KeyboardEvent) => { - if (e.key === "f") { - setBoardOrientation((prev) => !prev); - } - }; + useEffect(() => { + const onKeyDown = (e: KeyboardEvent) => { + if (e.key === "f") { + setBoardOrientation((prev) => !prev); + } + }; - window.addEventListener("keydown", onKeyDown); + window.addEventListener("keydown", onKeyDown); + + return () => { + window.removeEventListener("keydown", onKeyDown); + }; + }, [setBoardOrientation]); - return () => { - window.removeEventListener("keydown", onKeyDown); - }; - }, []); - return (