feat: add vote ratio bar

This commit is contained in:
James Xylight committed 2025-07-31 23:05:59 -07:00
1 parent 7ef9da9852
commit d6d1a9fe1f
6 files changed
+63 -3

No files matched your search

@@ -96,7 +96,7 @@
contentClass={[
(node.children.length > 0 ||
node.comment_view.counts.child_count > 0) &&
'border-l-2',
'border-l',
'ml-2.5 pl-3 sm:pl-4 lg:pl-5',
node.depth % 2 == 0
? 'border-slate-200 dark:border-zinc-800'
@@ -8,6 +8,7 @@
import { backOut } from 'svelte/easing'
import { fly } from 'svelte/transition'
import { shouldShowVoteColor } from '../post/PostVote.svelte'
import { settings } from '$lib/settings.svelte'
interface Props {
vote?: number
@@ -36,13 +37,19 @@
})
;({ upvotes, downvotes } = res.comment_view.counts)
}
let voteRatio = $derived(
Math.floor(((upvotes ?? 0) / ((upvotes ?? 0) + (downvotes ?? 0))) * 100),
)
</script>
<div
class={[
'h-full flex items-center overflow-hidden rounded-full hover:bg-transparent font-medium hover:dark:bg-transparent',
'h-full relative flex items-center overflow-hidden rounded-full hover:bg-transparent font-medium hover:dark:bg-transparent',
buttonColor.ghost,
voteRatio < 85 && settings.voteRatioBar && 'vote-ratio',
]}
style="--vote-ratio: {voteRatio}%;"
>
<button
onclick={() => castVote(vote == 1 ? 0 : 1)}
@@ -92,3 +99,20 @@
</span>
</button>
</div>
<style>
.vote-ratio::before {
content: '';
position: absolute;
height: 1px;
width: 100%;
left: 0;
bottom: 0px;
z-index: 10;
background: linear-gradient(
to right,
var(--color-indigo-500) calc(var(--vote-ratio) - 5%),
var(--color-red-500) calc(var(--vote-ratio) + 5%)
);
}
</style>