From a3bca7ff0b3791dea99cc9bd3eacb0385be8da99 Mon Sep 17 00:00:00 2001 From: Francisco Salgueiro Date: Wed, 29 Nov 2023 22:32:48 +0000 Subject: [PATCH] fix shortcut changing --- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src/components/TopBar.tsx | 9 ++-- src/components/boards/Board.tsx | 4 +- src/components/common/MoveControls.tsx | 14 +++-- src/components/databases/GamePreview.tsx | 8 ++- src/components/databases/PlayerTable.tsx | 54 +++++++++----------- src/components/databases/TournamentTable.tsx | 54 +++++++++----------- 9 files changed, 64 insertions(+), 85 deletions(-) diff --git a/package.json b/package.json index 45eb593e..963932a5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "en-croissant", "private": true, - "version": "0.7.0", + "version": "0.7.1", "type": "module", "scripts": { "start": "vite", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 275228c9..ae95fe49 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1073,7 +1073,7 @@ checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7" [[package]] name = "en-croissant" -version = "0.7.0" +version = "0.7.1" dependencies = [ "axum", "bincode", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 67d998de..6134470b 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "en-croissant" -version = "0.7.0" +version = "0.7.1" description = "A Modern Chess Database" authors = ["Francisco Salgueiro "] license = "GPL-3.0-only" diff --git a/src/components/TopBar.tsx b/src/components/TopBar.tsx index e564c7ec..9b750ead 100644 --- a/src/components/TopBar.tsx +++ b/src/components/TopBar.tsx @@ -19,8 +19,9 @@ import { useAtom, useAtomValue } from "jotai"; import { useNavigate } from "react-router-dom"; import AboutModal from "./About"; import { useState } from "react"; +import { useHotkeys } from "react-hotkeys-hook"; import { createTab } from "@/utils/tabs"; -import { useHotkeys } from "@mantine/hooks"; + import { keyMapAtom } from "@/atoms/keybinds"; function IconMinimize() { @@ -198,10 +199,8 @@ function TopBar() { const { classes } = useStyles(); const [opened, setOpened] = useState(false); - useHotkeys([ - [keyMap.NEW_TAB.keys, createNewTab], - [keyMap.OPEN_FILE.keys, openNewFile], - ]); + useHotkeys(keyMap.NEW_TAB.keys, createNewTab); + useHotkeys(keyMap.OPEN_FILE.keys, openNewFile); const theme = useMantineTheme(); diff --git a/src/components/boards/Board.tsx b/src/components/boards/Board.tsx index 0ddeb586..a15a77aa 100644 --- a/src/components/boards/Board.tsx +++ b/src/components/boards/Board.tsx @@ -38,7 +38,7 @@ import { Input, Tooltip, } from "@mantine/core"; -import { useHotkeys } from "@mantine/hooks"; +import { useHotkeys } from "react-hotkeys-hook"; import { IconChessBishopFilled, IconChessFilled, @@ -152,7 +152,7 @@ function Board({ }); const keyMap = useAtomValue(keyMapAtom); - useHotkeys([[keyMap.SWAP_ORIENTATION.keys, () => toggleOrientation()]]); + useHotkeys(keyMap.SWAP_ORIENTATION.keys, () => toggleOrientation()); const [currentTab, setCurrentTab] = useAtom(currentTabAtom); const practicing = useAtomValue(currentPracticingAtom); diff --git a/src/components/common/MoveControls.tsx b/src/components/common/MoveControls.tsx index 412bbeae..fa1f6e51 100644 --- a/src/components/common/MoveControls.tsx +++ b/src/components/common/MoveControls.tsx @@ -1,5 +1,5 @@ import { ActionIcon, Group } from "@mantine/core"; -import { useHotkeys } from "@mantine/hooks"; +import { useHotkeys } from "react-hotkeys-hook"; import { IconChevronLeft, IconChevronRight, @@ -30,13 +30,11 @@ function MoveControls({ goToPrevious ?? (() => dispatch({ type: "GO_TO_PREVIOUS" })); const handleGoToNext = goToNext ?? (() => dispatch({ type: "GO_TO_NEXT" })); const keyMap = useAtomValue(keyMapAtom); - useHotkeys([ - [keyMap.PREVIOUS_MOVE.keys, handleGoToPrevious], - [keyMap.NEXT_MOVE.keys, handleGoToNext], - [keyMap.GO_TO_START.keys, handleGoToStart], - [keyMap.GO_TO_END.keys, handleGoToEnd], - [keyMap.DELETE_MOVE.keys, () => dispatch({ type: "DELETE_MOVE" })], - ]); + useHotkeys(keyMap.PREVIOUS_MOVE.keys, handleGoToPrevious); + useHotkeys(keyMap.NEXT_MOVE.keys, handleGoToNext); + useHotkeys(keyMap.GO_TO_START.keys, handleGoToStart); + useHotkeys(keyMap.GO_TO_END.keys, handleGoToEnd); + useHotkeys(keyMap.DELETE_MOVE.keys, () => dispatch({ type: "DELETE_MOVE" })); return ( diff --git a/src/components/databases/GamePreview.tsx b/src/components/databases/GamePreview.tsx index 52e8a111..17940707 100644 --- a/src/components/databases/GamePreview.tsx +++ b/src/components/databases/GamePreview.tsx @@ -1,5 +1,5 @@ import { Box, Group, Stack, Text } from "@mantine/core"; -import { useHotkeys } from "@mantine/hooks"; +import { useHotkeys } from "react-hotkeys-hook"; import { useContext } from "react"; import { Chessground } from "@/chessground/Chessground"; import MoveControls from "../common/MoveControls"; @@ -63,10 +63,8 @@ function GamePreview({ const [treeState, dispatch] = useImmerReducer(treeReducer, game); const keyMap = useAtomValue(keyMapAtom); - useHotkeys([ - [keyMap.PREVIOUS_MOVE.keys, () => dispatch({ type: "GO_TO_PREVIOUS" })], - [keyMap.NEXT_MOVE.keys, () => dispatch({ type: "GO_TO_NEXT" })], - ]); + useHotkeys(keyMap.PREVIOUS_MOVE.keys, () => dispatch({ type: "GO_TO_PREVIOUS" })); + useHotkeys(keyMap.NEXT_MOVE.keys, () => dispatch({ type: "GO_TO_NEXT" })); return ( diff --git a/src/components/databases/PlayerTable.tsx b/src/components/databases/PlayerTable.tsx index 7d8441a1..1b6b5630 100644 --- a/src/components/databases/PlayerTable.tsx +++ b/src/components/databases/PlayerTable.tsx @@ -8,7 +8,7 @@ import { Text, TextInput, } from "@mantine/core"; -import { useHotkeys } from "@mantine/hooks"; +import { useHotkeys } from "react-hotkeys-hook"; import { IconDotsVertical, IconSearch } from "@tabler/icons-react"; import { DataTable, DataTableSortStatus } from "mantine-datatable"; import { useEffect, useState } from "react"; @@ -70,36 +70,28 @@ function PlayerTable({ database }: { database: DatabaseInfo }) { }); }, [activePage, sort]); - useHotkeys([ - [ - "ArrowUp", - () => { - setSelectedPlayer((prev) => { - if (prev === null) { - return null; - } - if (prev === 0) { - return 0; - } - return prev - 1; - }); - }, - ], - [ - "ArrowDown", - () => { - setSelectedPlayer((prev) => { - if (prev === null) { - return 0; - } - if (prev === players.length - 1) { - return players.length - 1; - } - return prev + 1; - }); - }, - ], - ]); + useHotkeys("ArrowUp", () => { + setSelectedPlayer((prev) => { + if (prev === null) { + return null; + } + if (prev === 0) { + return 0; + } + return prev - 1; + }); + }); + useHotkeys("ArrowDown", () => { + setSelectedPlayer((prev) => { + if (prev === null) { + return 0; + } + if (prev === players.length - 1) { + return players.length - 1; + } + return prev + 1; + }); + }); return ( { - setSelected((prev) => { - if (prev === null) { - return null; - } - if (prev === 0) { - return 0; - } - return prev - 1; - }); - }, - ], - [ - "ArrowDown", - () => { - setSelected((prev) => { - if (prev === null) { - return 0; - } - if (prev === tournaments.length - 1) { - return tournaments.length - 1; - } - return prev + 1; - }); - }, - ], - ]); + useHotkeys("ArrowUp", () => { + setSelected((prev) => { + if (prev === null) { + return null; + } + if (prev === 0) { + return 0; + } + return prev - 1; + }); + }); + useHotkeys("ArrowDown", () => { + setSelected((prev) => { + if (prev === null) { + return 0; + } + if (prev === tournaments.length - 1) { + return tournaments.length - 1; + } + return prev + 1; + }); + }); return (