Skip to content

Commit

Permalink
fix shortcut changing
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Nov 29, 2023
1 parent 21d538f commit a3bca7f
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 85 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "en-croissant",
"private": true,
"version": "0.7.0",
"version": "0.7.1",
"type": "module",
"scripts": {
"start": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "en-croissant"
version = "0.7.0"
version = "0.7.1"
description = "A Modern Chess Database"
authors = ["Francisco Salgueiro <[email protected]>"]
license = "GPL-3.0-only"
Expand Down
9 changes: 4 additions & 5 deletions src/components/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/components/boards/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
Input,
Tooltip,
} from "@mantine/core";
import { useHotkeys } from "@mantine/hooks";
import { useHotkeys } from "react-hotkeys-hook";
import {
IconChessBishopFilled,
IconChessFilled,
Expand Down Expand Up @@ -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);

Expand Down
14 changes: 6 additions & 8 deletions src/components/common/MoveControls.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActionIcon, Group } from "@mantine/core";
import { useHotkeys } from "@mantine/hooks";
import { useHotkeys } from "react-hotkeys-hook";
import {
IconChevronLeft,
IconChevronRight,
Expand Down Expand Up @@ -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 (
<Group grow>
<ActionIcon variant="default" size="xl" onClick={handleGoToStart}>
Expand Down
8 changes: 3 additions & 5 deletions src/components/databases/GamePreview.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 (
<TreeStateContext.Provider value={treeState}>
Expand Down
54 changes: 23 additions & 31 deletions src/components/databases/PlayerTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 (
<GridLayout
Expand Down
54 changes: 23 additions & 31 deletions src/components/databases/TournamentTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Center, Flex, Text, TextInput } from "@mantine/core";
import { useHotkeys } from "@mantine/hooks";
import { useHotkeys } from "react-hotkeys-hook";
import { IconSearch } from "@tabler/icons-react";
import { DataTable, DataTableSortStatus } from "mantine-datatable";
import { useEffect, useState } from "react";
Expand Down Expand Up @@ -57,36 +57,28 @@ function TournamentTable({ database }: { database: DatabaseInfo }) {
});
}, [activePage, sort]);

useHotkeys([
[
"ArrowUp",
() => {
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 (
<GridLayout
Expand Down

0 comments on commit a3bca7f

Please sign in to comment.