diff --git a/src/lib/components/lemmy/PostVote.svelte b/src/lib/components/lemmy/PostVote.svelte index d4a4aa93..f893a891 100644 --- a/src/lib/components/lemmy/PostVote.svelte +++ b/src/lib/components/lemmy/PostVote.svelte @@ -13,6 +13,16 @@ const upvoted = vote == 1 + if (vote == -1) { + score += 2 + } else if (vote == 1) { + score -= 1 + } else if (vote == 0) { + score += 1 + } + + vote = Number(!upvoted) + await getClient() .likePost({ score: upvoted ? 0 : 1, @@ -27,6 +37,16 @@ const upvoted = vote == -1 + if (vote == -1) { + score += 1 + } else if (vote == 1) { + score -= 2 + } else if (vote == 0) { + score -= 1 + } + + vote = -Number(!upvoted) + await getClient() .likePost({ score: upvoted ? 0 : -1, @@ -50,27 +70,13 @@ : // no vote 'bg-slate-100 dark:bg-zinc-800 hover:bg-slate-200 dark:hover:bg-zinc-700'}" > - - diff --git a/src/lib/components/lemmy/comment/Comment.svelte b/src/lib/components/lemmy/comment/Comment.svelte index d27d9778..d4a68021 100644 --- a/src/lib/components/lemmy/comment/Comment.svelte +++ b/src/lib/components/lemmy/comment/Comment.svelte @@ -25,11 +25,21 @@ export let open = true export let replying = false + let score = node.comment_view.counts.score + async function upvote() { if (!$authData) return const upvoted = node.comment_view.my_vote == 1 + if (node.comment_view.my_vote == -1) { + score += 2 + } else if (node.comment_view.my_vote == 1) { + score -= 1 + } else if (node.comment_view.my_vote == 0) { + score += 1 + } + node.comment_view.my_vote = Number(!upvoted) await getClient() @@ -46,6 +56,14 @@ const upvoted = node.comment_view.my_vote == -1 + if (node.comment_view.my_vote == -1) { + score += 1 + } else if (node.comment_view.my_vote == 1) { + score -= 2 + } else if (node.comment_view.my_vote == 0) { + score -= 1 + } + node.comment_view.my_vote = -Number(!upvoted) await getClient() @@ -71,12 +89,6 @@ - @@ -117,7 +129,7 @@ - {node.comment_view.counts.score} + {score}