fix: Fix number change on vote for comments
This commit is contained in:
1 parent
f037d800c5
commit
cae8011d68
2 files changed
+10
-7
No files matched your search
@@ -5,7 +5,7 @@
|
|||||||
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
|
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let post: Post
|
export let post: Post
|
||||||
export let vote: number | undefined
|
export let vote: number = 0
|
||||||
export let score: number
|
export let score: number
|
||||||
|
|
||||||
async function upvote() {
|
async function upvote() {
|
||||||
|
|||||||
@@ -26,20 +26,22 @@
|
|||||||
export let replying = false
|
export let replying = false
|
||||||
|
|
||||||
let score = node.comment_view.counts.score
|
let score = node.comment_view.counts.score
|
||||||
|
let vote = node.comment_view.my_vote ?? 0
|
||||||
|
|
||||||
async function upvote() {
|
async function upvote() {
|
||||||
if (!$authData) return
|
if (!$authData) return
|
||||||
|
|
||||||
const upvoted = node.comment_view.my_vote == 1
|
const upvoted = node.comment_view.my_vote == 1
|
||||||
|
|
||||||
if (node.comment_view.my_vote == -1) {
|
if (vote == -1) {
|
||||||
score += 2
|
score += 2
|
||||||
} else if (node.comment_view.my_vote == 1) {
|
} else if (vote == 1) {
|
||||||
score -= 1
|
score -= 1
|
||||||
} else if (node.comment_view.my_vote == 0) {
|
} else if (vote == 0) {
|
||||||
score += 1
|
score += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vote = Number(!upvoted)
|
||||||
node.comment_view.my_vote = Number(!upvoted)
|
node.comment_view.my_vote = Number(!upvoted)
|
||||||
|
|
||||||
await getClient()
|
await getClient()
|
||||||
@@ -56,14 +58,15 @@
|
|||||||
|
|
||||||
const upvoted = node.comment_view.my_vote == -1
|
const upvoted = node.comment_view.my_vote == -1
|
||||||
|
|
||||||
if (node.comment_view.my_vote == -1) {
|
if (vote == -1) {
|
||||||
score += 1
|
score += 1
|
||||||
} else if (node.comment_view.my_vote == 1) {
|
} else if (vote == 1) {
|
||||||
score -= 2
|
score -= 2
|
||||||
} else if (node.comment_view.my_vote == 0) {
|
} else if (vote == 0) {
|
||||||
score -= 1
|
score -= 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vote = -Number(!upvoted)
|
||||||
node.comment_view.my_vote = -Number(!upvoted)
|
node.comment_view.my_vote = -Number(!upvoted)
|
||||||
|
|
||||||
await getClient()
|
await getClient()
|
||||||
|
|||||||
Reference in new issue
Block a user