Skip to content

Commit 96277e0

Browse files
authored
Hotkeys for starting game (#144)
* Closes #136 is this how you add a newline in JSX i have no idea lol * Also hotkey for RoomPage.js * drop: remove hotkey labels * feat: play again hotkey * doc: put hotkey shortcut in help
1 parent 8fa292f commit 96277e0

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/pages/GamePage.js

+11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import User from "../components/User";
2222
import { SettingsContext, UserContext } from "../context";
2323
import firebase, { createGame, fetchStaleGame, finishGame } from "../firebase";
2424
import useFirebaseRef from "../hooks/useFirebaseRef";
25+
import useKeydown from "../hooks/useKeydown";
2526
import {
2627
checkSet,
2728
checkSetUltra,
@@ -151,6 +152,16 @@ function GamePage() {
151152
}
152153
}, [loadingGame, loadingGameData, game, gameData, fetchingStaleGame, gameId]);
153154

155+
useKeydown((event) => {
156+
if (
157+
event.ctrlKey === true &&
158+
event.keyCode === 13 &&
159+
game.status === "done"
160+
) {
161+
handlePlayAgain();
162+
}
163+
});
164+
154165
if (redirect) return <Navigate push to={redirect} />;
155166

156167
if (

src/pages/HelpPage.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,12 @@ function HelpPage() {
171171
shortcuts by selecting your keyboard layout in the settings. The
172172
shortcuts specific to your layout will then be reflected here.
173173
</Typography>
174-
174+
<Typography variant="body1" gutterBottom>
175+
You can start a room with the <code>Ctrl + Enter</code> shortcut from
176+
the lobby, and start or restart a game with <code>Ctrl + Enter</code>.
177+
From the lobby you can also start a private room with{" "}
178+
<code>Shift + Enter</code>.
179+
</Typography>
175180
<hr />
176181
<Typography variant="h5" gutterBottom>
177182
Game modes

src/pages/LobbyPage.js

+18
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { UserContext } from "../context";
2525
import firebase, { createGame } from "../firebase";
2626
import useFirebaseQuery from "../hooks/useFirebaseQuery";
2727
import useFirebaseRef from "../hooks/useFirebaseRef";
28+
import useKeydown from "../hooks/useKeydown";
2829

2930
const useStyles = makeStyles((theme) => ({
3031
mainGrid: {
@@ -155,6 +156,23 @@ function LobbyPage() {
155156
setTabValue(newValue);
156157
};
157158

159+
useKeydown((event) => {
160+
if (
161+
event.ctrlKey === true &&
162+
event.shiftKey === false &&
163+
event.keyCode === 13
164+
) {
165+
newRoom("public");
166+
}
167+
if (
168+
event.ctrlKey === false &&
169+
event.shiftKey === true &&
170+
event.keyCode === 13
171+
) {
172+
newRoom("private");
173+
}
174+
});
175+
158176
if (redirect) return <Navigate push to={redirect} />;
159177

160178
async function newRoom(access) {

src/pages/RoomPage.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Subheading from "../components/Subheading";
2525
import { UserContext } from "../context";
2626
import firebase from "../firebase";
2727
import useFirebaseRef from "../hooks/useFirebaseRef";
28+
import useKeydown from "../hooks/useKeydown";
2829
import LoadingPage from "./LoadingPage";
2930
import NotFoundPage from "./NotFoundPage";
3031

@@ -89,6 +90,12 @@ function RoomPage() {
8990
}
9091
}, [user.id, game, gameId, leaving]);
9192

93+
useKeydown((event) => {
94+
if (event.ctrlKey === true && event.keyCode === 13) {
95+
startGame();
96+
}
97+
});
98+
9299
if (loadingGame) {
93100
return <LoadingPage />;
94101
}
@@ -131,7 +138,6 @@ function RoomPage() {
131138
setLeaving(false);
132139
});
133140
}
134-
135141
return (
136142
<Container sx={{ pb: 2 }}>
137143
<Grid container spacing={2}>

0 commit comments

Comments
 (0)