feat: add popover to show vote counts
This commit is contained in:
1 parent
04b31af0de
commit
8afd3b25ca
5 files changed
+71
-50
No files matched your search
@@ -1,11 +1,11 @@
|
||||
<script lang="ts">
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import { getClient } from '$lib/lemmy'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import {
|
||||
ArrowDown,
|
||||
ArrowDownCircle,
|
||||
ArrowUp,
|
||||
ArrowUpCircle,
|
||||
ChevronDown,
|
||||
ChevronUp,
|
||||
@@ -13,10 +13,12 @@
|
||||
} from 'svelte-hero-icons'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { vote as voteItem } from '$lib/lemmy/contentview.js'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { Button, Popover } from 'mono-svelte'
|
||||
|
||||
export let post: Post
|
||||
export let vote: number = 0
|
||||
export let upvotes: number = 0
|
||||
export let downvotes: number = 0
|
||||
export let score: number
|
||||
|
||||
const voteColor = (vote: number) =>
|
||||
@@ -66,42 +68,55 @@
|
||||
</Button>
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="flex items-center text-sm gap-1 rounded-md border border-slate-200
|
||||
dark:border-zinc-700 px-1 h-full duration-200 dark:bg-zinc-900"
|
||||
>
|
||||
<Button
|
||||
aria-label="Upvote"
|
||||
class={vote == 1 ? voteColor(vote) : ''}
|
||||
on:click={async () => {
|
||||
if (!$profile?.jwt) return
|
||||
score = await voteItem(post, vote == 1 ? 0 : 1, $profile.jwt)
|
||||
vote = vote == 1 ? 0 : 1
|
||||
}}
|
||||
size="square-sm"
|
||||
color="tertiary"
|
||||
alignment="center"
|
||||
<Popover targetClass="h-8" openOnHover>
|
||||
<div
|
||||
class="flex items-center text-sm gap-1 rounded-md border border-slate-200
|
||||
dark:border-zinc-700 px-1 h-8 duration-200 dark:bg-zinc-900"
|
||||
slot="target"
|
||||
>
|
||||
<Icon src={ChevronUp} mini size="18" />
|
||||
</Button>
|
||||
<span
|
||||
class="font-medium transition-colors duration-200 {voteColor(vote)}"
|
||||
>
|
||||
<FormattedNumber number={score} />
|
||||
</span>
|
||||
<Button
|
||||
aria-label="Downvote"
|
||||
class={vote == -1 ? voteColor(vote) : ''}
|
||||
on:click={async () => {
|
||||
if (!$profile?.jwt) return
|
||||
score = await voteItem(post, vote == -1 ? 0 : -1, $profile.jwt)
|
||||
vote = vote == -1 ? 0 : -1
|
||||
}}
|
||||
size="square-sm"
|
||||
color="tertiary"
|
||||
>
|
||||
<Icon src={ChevronDown} mini size="18" />
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
aria-label="Upvote"
|
||||
class={vote == 1 ? voteColor(vote) : ''}
|
||||
on:click={async () => {
|
||||
if (!$profile?.jwt) return
|
||||
score = await voteItem(post, vote == 1 ? 0 : 1, $profile.jwt)
|
||||
vote = vote == 1 ? 0 : 1
|
||||
}}
|
||||
size="square-sm"
|
||||
color="tertiary"
|
||||
alignment="center"
|
||||
>
|
||||
<Icon src={ChevronUp} mini size="18" />
|
||||
</Button>
|
||||
<span
|
||||
class="font-medium transition-colors duration-200 {voteColor(vote)}"
|
||||
>
|
||||
<FormattedNumber number={score} />
|
||||
</span>
|
||||
<Button
|
||||
aria-label="Downvote"
|
||||
class={vote == -1 ? voteColor(vote) : ''}
|
||||
on:click={async () => {
|
||||
if (!$profile?.jwt) return
|
||||
score = await voteItem(post, vote == -1 ? 0 : -1, $profile.jwt)
|
||||
vote = vote == -1 ? 0 : -1
|
||||
}}
|
||||
size="square-sm"
|
||||
color="tertiary"
|
||||
>
|
||||
<Icon src={ChevronDown} mini size="18" />
|
||||
</Button>
|
||||
</div>
|
||||
<div class="flex flex-row items-center gap-2">
|
||||
<span class="flex items-center gap-1 text-blue-500 font-medium">
|
||||
<Icon src={ArrowUp} mini size="18" />
|
||||
<FormattedNumber number={upvotes} />
|
||||
</span>
|
||||
<span class="flex items-center gap-1 text-red-500 font-medium">
|
||||
<Icon src={ArrowDown} mini size="18" />
|
||||
<FormattedNumber number={downvotes} />
|
||||
</span>
|
||||
</div>
|
||||
</Popover>
|
||||
{/if}
|
||||
</slot>
|
||||
Reference in new issue
Block a user