diff --git a/src/ss_backend/main.mo b/src/ss_backend/main.mo index 96934d0..be7ed5e 100644 --- a/src/ss_backend/main.mo +++ b/src/ss_backend/main.mo @@ -294,13 +294,15 @@ actor { switch (currUser) { case (#ok(currUser)) { let post = await getPostById(postId); + var newPositive = 0; + var newNegative = 0; switch (post) { case (#ok(post)) { - var newPositive = post.positiveVotes; - var newNegative = post.negativeVotes; - if (sentiment == "Yes") { + newPositive := post.positiveVotes; + newNegative := post.negativeVotes; + if (sentiment == "No") { newPositive += 1; - } else if (sentiment == "No") { + } else if (sentiment == "Yes") { newNegative += 1; }; if (newPositive + newNegative >= 3) { @@ -335,7 +337,7 @@ actor { }; }; // comments.put(newId, comment); - return #ok("Voted"); + return #ok("negative votes" # Nat.toText(newNegative) # sentiment); }; case (#err(error)) { diff --git a/src/ss_frontend/src/components/HomePost.jsx b/src/ss_frontend/src/components/HomePost.jsx index e503d2d..151d3d9 100644 --- a/src/ss_frontend/src/components/HomePost.jsx +++ b/src/ss_frontend/src/components/HomePost.jsx @@ -42,6 +42,8 @@ const HomePost = ({ post, choosePost, refetch }) => { async function handleVote(sentiment){ const result = await ss_backend.votePost(principal, post.id, sentiment); + console.log(result); + refetch(); }