mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-30 23:27:55 -05:00
Rename vote function
This commit is contained in:
@@ -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 }),
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user