Rename vote function

This commit is contained in:
Kalle
2022-06-12 16:41:33 +03:00
parent 010f709e4b
commit b39c3b745f
2 changed files with 6 additions and 7 deletions

View File

@@ -18,7 +18,7 @@ export function usePlusVoting(usersForVotingFromServer: UsersForVoting) {
const [usersForVoting, setUsersForVoting] = React.useState<UsersForVoting>();
const [votes, setVotes] = React.useState<PlusVoteFromFE[]>([]);
const vote = React.useCallback(
const addVote = React.useCallback(
(type: "upvote" | "downvote") => {
setVotes((votes) => {
const votedId = usersForVoting?.[votes.length]?.user.id;
@@ -53,7 +53,7 @@ export function usePlusVoting(usersForVotingFromServer: UsersForVoting) {
setVotes,
});
useVoteWithArrowKeysEffect(vote);
useVoteWithArrowKeysEffect(addVote);
const currentUser = usersForVoting?.[votes.length];
@@ -61,9 +61,8 @@ export function usePlusVoting(usersForVotingFromServer: UsersForVoting) {
usersForVoting ? [votes.length, usersForVoting.length] : undefined;
return {
// xxx: rename one of these -> both similar name but completely different
votes,
vote,
addVote,
undoLast,
currentUser,
previous: previousUser({ usersForVoting, votes }),

View File

@@ -182,7 +182,7 @@ const tips = [
function Voting(data: Extract<PlusVotingLoaderData, { type: "voting" }>) {
const [randomTip] = React.useState(tips[Math.floor(Math.random() * 3)]);
const { currentUser, previous, votes, vote, undoLast, isReady, progress } =
const { currentUser, previous, votes, addVote, undoLast, isReady, progress } =
usePlusVoting(data.usersForVoting);
if (!isReady) return null;
@@ -224,14 +224,14 @@ function Voting(data: Extract<PlusVotingLoaderData, { type: "voting" }>) {
<Button
className="plus-voting__vote-button downvote"
variant="outlined"
onClick={() => vote("downvote")}
onClick={() => addVote("downvote")}
>
-1
</Button>
<Button
className="plus-voting__vote-button"
variant="outlined"
onClick={() => vote("upvote")}
onClick={() => addVote("upvote")}
>
+1
</Button>