Vote with S/K keys instead of < > keys

This commit is contained in:
Kalle
2022-07-02 14:22:10 +03:00
parent 921a0576b1
commit 6438d1a781
2 changed files with 6 additions and 8 deletions

View File

@@ -55,7 +55,7 @@ export function usePlusVoting(usersForVotingFromServer: UsersForVoting) {
setVotes,
});
useVoteWithArrowKeysEffect(addVote);
useVoteWithKeysEffect(addVote);
const currentUser = usersForVoting?.[votes.length];
@@ -133,15 +133,13 @@ function useLoadInitialStateFromLocalStorageEffect({
}, [month, year, usersForVotingFromServer, setUsersForVoting, setVotes]);
}
function useVoteWithArrowKeysEffect(
vote: (type: "upvote" | "downvote") => void
) {
function useVoteWithKeysEffect(vote: (type: "upvote" | "downvote") => void) {
React.useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if (e.code === "ArrowRight") {
vote("upvote");
} else if (e.code === "ArrowLeft") {
if (e.code === "KeyS") {
vote("downvote");
} else if (e.code === "KeyK") {
vote("upvote");
}
};

View File

@@ -199,7 +199,7 @@ function VotingTimingInfo(
const tips = [
"Voting progress is saved locally",
"Use left and right arrows on desktop to vote",
"Use S (-1) and K (+1) arrows on desktop to vote",
"You +1 yourself automatically",
];