Skip to content

Commit

Permalink
feats/fix vote
Browse files Browse the repository at this point in the history
  • Loading branch information
wantouw committed Aug 23, 2024
1 parent f7feafe commit 0108674
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/ss_backend/main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -335,7 +337,7 @@ actor {
};
};
// comments.put(newId, comment);
return #ok("Voted");
return #ok("negative votes" # Nat.toText(newNegative) # sentiment);

};
case (#err(error)) {
Expand Down
2 changes: 2 additions & 0 deletions src/ss_frontend/src/components/HomePost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 0108674

Please sign in to comment.