feat: add popover to show vote counts

This commit is contained in:
Xyphyn committed 2023-09-03 19:54:46 -07:00
1 parent 04b31af0de
commit 8afd3b25ca
5 files changed
+71 -50

No files matched your search

@@ -75,6 +75,8 @@
<PostVote
post={post.post}
bind:vote={post.my_vote}
bind:upvotes={post.counts.upvotes}
bind:downvotes={post.counts.downvotes}
bind:score={post.counts.score}
/>
@@ -107,7 +109,11 @@
{#if $profile?.user && (amMod($profile.user, post.community) || isAdmin($profile.user))}
<ModerationMenu bind:item={post} community={post.community} />
{/if}
<Menu alignment="bottom-right" containerClass="overflow-auto max-h-[400px]">
<Menu
alignment="bottom-right"
containerClass="overflow-auto max-h-[400px]"
class="h-full max-h-screen"
>
<Button
let:toggleOpen
slot="button"
@@ -1,7 +1,7 @@
<script lang="ts">
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import Badge from '$lib/components/ui/Badge.svelte'
import { Badge } from 'mono-svelte'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import type { Community, Person } from 'lemmy-js-client'
@@ -68,16 +68,16 @@
<div class="flex flex-row ml-auto gap-2 flex-wrap">
{#if nsfw}
<Badge color="red">NSFW</Badge>
<Badge color="red-subtle">NSFW</Badge>
{/if}
{#if saved}
<Badge label="Saved" color="yellow">
<Badge label="Saved" color="yellow-subtle">
<Icon src={Bookmark} mini size="12" />
Saved
</Badge>
{/if}
{#if locked}
<Badge label="Locked" color="yellow">
<Badge label="Locked" color="yellow-subtle">
<Icon src={LockClosed} mini size="14" />
Locked
</Badge>
@@ -89,7 +89,7 @@
</Badge>
{/if}
{#if deleted}
<Badge label="Deleted" color="red">
<Badge label="Deleted" color="red-subtle">
<Icon src={Trash} mini size="14" />
Deleted
</Badge>
+54 -39
View File
@@ -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>