Skip to content

Commit

Permalink
fix: race condition when vote
Browse files Browse the repository at this point in the history
  • Loading branch information
basiooo committed Apr 7, 2024
1 parent bf99495 commit 6294f23
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/hooks/UseVote.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ export const useVote = () => {
neutralizeDownVote,
data
}) => {
const handleUpVote = () => {
const handleUpVote = async () => {
if (!auth) {
return
}
if (upVotesBy.includes(auth.id)) {
neutralizeUpVote(data)
await neutralizeUpVote(data)
} else {
neutralizeDownVote(data)
upVote(data)
await neutralizeDownVote(data)
await upVote(data)
}
}

const handleDownVote = () => {
const handleDownVote = async () => {
if (!auth) {
return
}
if (downVotesBy.includes(auth.id)) {
neutralizeDownVote(data)
await neutralizeDownVote(data)
} else {
neutralizeUpVote(data)
downVote(data)
await neutralizeUpVote(data)
await downVote(data)
}
}
return {
Expand Down

0 comments on commit 6294f23

Please sign in to comment.