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"
|
size="square-lg"
|
||||||
disabled={!getSessionStorage('postDraft')}
|
disabled={!getSessionStorage('postDraft')}
|
||||||
|
title="Restore From Draft"
|
||||||
>
|
>
|
||||||
<Icon src={ArrowPath} size="16" mini />
|
<Icon src={ArrowPath} size="16" mini />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -35,6 +35,8 @@
|
|||||||
export let upvotes: number = 0
|
export let upvotes: number = 0
|
||||||
export let downvotes: number = 0
|
export let downvotes: number = 0
|
||||||
|
|
||||||
|
let loading = false
|
||||||
|
|
||||||
let oldScore = score
|
let oldScore = score
|
||||||
|
|
||||||
const castVote = async (newVote: number) => {
|
const castVote = async (newVote: number) => {
|
||||||
@@ -42,17 +44,20 @@
|
|||||||
toast({ content: 'You must be logged in to vote.', type: 'warning' })
|
toast({ content: 'You must be logged in to vote.', type: 'warning' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
loading = true
|
||||||
oldScore = score
|
oldScore = score
|
||||||
vote = newVote
|
vote = newVote
|
||||||
const res = await voteItem(post, newVote, $profile.jwt)
|
const res = await voteItem(post, newVote, $profile.jwt)
|
||||||
;({ upvotes, downvotes, score } = res)
|
;({ upvotes, downvotes, score } = res)
|
||||||
|
loading = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<slot {vote} {score}>
|
<slot {vote} {score}>
|
||||||
<div
|
<div
|
||||||
class="{buttonColor.secondary} rounded-lg h-full flex items-center [&>*]:p-2
|
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
|
<button
|
||||||
on:click={() => castVote(vote == 1 ? 0 : 1)}
|
on:click={() => castVote(vote == 1 ? 0 : 1)}
|
||||||
|
|||||||
Reference in new issue
Block a user