Skip to content

Commit

Permalink
set user likes with refetched data
Browse files Browse the repository at this point in the history
  • Loading branch information
GraemeFulton committed Jun 13, 2024
1 parent 54d639b commit 57739e6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions components/LikeButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,31 @@ const LikeButton = ({ post, user }) => {

useEffect(() => {
const updateLikes = async () => {

const likeObject = post.attributes?.likes?.data?.find(
like => like?.attributes?.user?.data?.id == user?.id
);
if (likeObject) {
setUserLikeObject(likeObject);
const { like, love, fire, unicorn } = likeObject.attributes;
setReactions({
like,
love,
fire,
unicorn,
});
} else {
setUserLikeObject(null);
setReactions({
like: false,
love: false,
fire: false,
unicorn: false,
});
}

await refetchLikeCount(post, user);

};
updateLikes();
}, [user, post]);
Expand Down

0 comments on commit 57739e6

Please sign in to comment.