feat: add load animation to votes
This commit is contained in:
1 parent
d3168c1d1d
commit
7d5328901b
2 files changed
+7
-1
No files matched your search
@@ -321,6 +321,7 @@
|
||||
}}
|
||||
size="square-lg"
|
||||
disabled={!getSessionStorage('postDraft')}
|
||||
title="Restore From Draft"
|
||||
>
|
||||
<Icon src={ArrowPath} size="16" mini />
|
||||
</Button>
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
export let upvotes: number = 0
|
||||
export let downvotes: number = 0
|
||||
|
||||
let loading = false
|
||||
|
||||
let oldScore = score
|
||||
|
||||
const castVote = async (newVote: number) => {
|
||||
@@ -42,17 +44,20 @@
|
||||
toast({ content: 'You must be logged in to vote.', type: 'warning' })
|
||||
return
|
||||
}
|
||||
loading = true
|
||||
oldScore = score
|
||||
vote = newVote
|
||||
const res = await voteItem(post, newVote, $profile.jwt)
|
||||
;({ upvotes, downvotes, score } = res)
|
||||
loading = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<slot {vote} {score}>
|
||||
<div
|
||||
class="{buttonColor.secondary} rounded-lg h-full flex items-center [&>*]:p-2
|
||||
hover:bg-white hover:dark:bg-zinc-900 overflow-hidden"
|
||||
hover:bg-white hover:dark:bg-zinc-900 overflow-hidden transition-colors
|
||||
{loading ? 'animate-pulse opacity-75 pointer-events-none' : ''}"
|
||||
>
|
||||
<button
|
||||
on:click={() => castVote(vote == 1 ? 0 : 1)}
|
||||
|
||||
Reference in new issue
Block a user