fix: Fix number change on vote for comments

This commit is contained in:
Xyphyn committed 2023-07-05 13:13:12 -07:00
1 parent f037d800c5
commit cae8011d68
2 files changed
+10 -7

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
export let post: Post
export let vote: number | undefined
export let vote: number = 0
export let score: number
async function upvote() {
@@ -26,20 +26,22 @@
export let replying = false
let score = node.comment_view.counts.score
let vote = node.comment_view.my_vote ?? 0
async function upvote() {
if (!$authData) return
const upvoted = node.comment_view.my_vote == 1
if (node.comment_view.my_vote == -1) {
if (vote == -1) {
score += 2
} else if (node.comment_view.my_vote == 1) {
} else if (vote == 1) {
score -= 1
} else if (node.comment_view.my_vote == 0) {
} else if (vote == 0) {
score += 1
}
vote = Number(!upvoted)
node.comment_view.my_vote = Number(!upvoted)
await getClient()
@@ -56,14 +58,15 @@
const upvoted = node.comment_view.my_vote == -1
if (node.comment_view.my_vote == -1) {
if (vote == -1) {
score += 1
} else if (node.comment_view.my_vote == 1) {
} else if (vote == 1) {
score -= 2
} else if (node.comment_view.my_vote == 0) {
} else if (vote == 0) {
score -= 1
}
vote = -Number(!upvoted)
node.comment_view.my_vote = -Number(!upvoted)
await getClient()