Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-ChoBab into feat/#196
  • Loading branch information
junghyunbak committed Dec 13, 2022
2 parents a477a4c + d31240a commit 94d4a03
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions client/src/components/RestaurantVoteButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ function RestaurantVoteButton({
return;
}

socket.on('userVoteRestaurantIdList', (result: VoteRestaurantListType) => {
const handleUserVoteRestaurantIdList = (result: VoteRestaurantListType) => {
votedRestaurantListRef.current = result.data.voteRestaurantIdList;
setIsVoted(votedRestaurantListRef.current.includes(restaurantId));
});
}

socket.on('cancelVoteRestaurantResult', (result: VoteResultType) => {
const handleCancelVoteRestaurantResult = (result: VoteResultType) => {
if (restaurantId !== result.data?.restaurantId) {
return;
}
Expand All @@ -76,9 +76,9 @@ function RestaurantVoteButton({
return;
}
setIsVoted(false);
});
}

socket.on('voteRestaurantResult', (result: VoteResultType) => {
const handleVoteRestaurantResult = (result: VoteResultType) => {
if (restaurantId !== result.data?.restaurantId) {
return;
}
Expand All @@ -93,9 +93,20 @@ function RestaurantVoteButton({
return;
}
setIsVoted(true);
});
}

socket.on('userVoteRestaurantIdList', handleUserVoteRestaurantIdList);
socket.on('cancelVoteRestaurantResult', handleCancelVoteRestaurantResult);
socket.on('voteRestaurantResult', handleVoteRestaurantResult);

setVotedRestaurantList();

// eslint-disable-next-line consistent-return
return () => {
socket.removeListener('userVoteRestaurantIdList', handleUserVoteRestaurantIdList);
socket.removeListener('voteRestaurantResult', handleVoteRestaurantResult);
socket.removeListener('cancelVoteRestaurantResult', handleCancelVoteRestaurantResult);
}
}, []);

const voteRestaurant = () => {
Expand Down

0 comments on commit 94d4a03

Please sign in to comment.