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
-1
@@ -42,7 +42,7 @@
|
|||||||
"@dicebear/initials": "^6.0.4",
|
"@dicebear/initials": "^6.0.4",
|
||||||
"lemmy-js-client": "^0.18.0-rc.2",
|
"lemmy-js-client": "^0.18.0-rc.2",
|
||||||
"markdown-it": "^13.0.1",
|
"markdown-it": "^13.0.1",
|
||||||
"mono-svelte": "^0.2.0"
|
"mono-svelte": "^0.2.2"
|
||||||
},
|
},
|
||||||
"type": "module"
|
"type": "module"
|
||||||
}
|
}
|
||||||
@@ -75,6 +75,8 @@
|
|||||||
<PostVote
|
<PostVote
|
||||||
post={post.post}
|
post={post.post}
|
||||||
bind:vote={post.my_vote}
|
bind:vote={post.my_vote}
|
||||||
|
bind:upvotes={post.counts.upvotes}
|
||||||
|
bind:downvotes={post.counts.downvotes}
|
||||||
bind:score={post.counts.score}
|
bind:score={post.counts.score}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -107,7 +109,11 @@
|
|||||||
{#if $profile?.user && (amMod($profile.user, post.community) || isAdmin($profile.user))}
|
{#if $profile?.user && (amMod($profile.user, post.community) || isAdmin($profile.user))}
|
||||||
<ModerationMenu bind:item={post} community={post.community} />
|
<ModerationMenu bind:item={post} community={post.community} />
|
||||||
{/if}
|
{/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
|
<Button
|
||||||
let:toggleOpen
|
let:toggleOpen
|
||||||
slot="button"
|
slot="button"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||||
import Avatar from '$lib/components/ui/Avatar.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 UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
import type { Community, Person } from 'lemmy-js-client'
|
import type { Community, Person } from 'lemmy-js-client'
|
||||||
@@ -68,16 +68,16 @@
|
|||||||
|
|
||||||
<div class="flex flex-row ml-auto gap-2 flex-wrap">
|
<div class="flex flex-row ml-auto gap-2 flex-wrap">
|
||||||
{#if nsfw}
|
{#if nsfw}
|
||||||
<Badge color="red">NSFW</Badge>
|
<Badge color="red-subtle">NSFW</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
{#if saved}
|
{#if saved}
|
||||||
<Badge label="Saved" color="yellow">
|
<Badge label="Saved" color="yellow-subtle">
|
||||||
<Icon src={Bookmark} mini size="12" />
|
<Icon src={Bookmark} mini size="12" />
|
||||||
Saved
|
Saved
|
||||||
</Badge>
|
</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
{#if locked}
|
{#if locked}
|
||||||
<Badge label="Locked" color="yellow">
|
<Badge label="Locked" color="yellow-subtle">
|
||||||
<Icon src={LockClosed} mini size="14" />
|
<Icon src={LockClosed} mini size="14" />
|
||||||
Locked
|
Locked
|
||||||
</Badge>
|
</Badge>
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
</Badge>
|
</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
{#if deleted}
|
{#if deleted}
|
||||||
<Badge label="Deleted" color="red">
|
<Badge label="Deleted" color="red-subtle">
|
||||||
<Icon src={Trash} mini size="14" />
|
<Icon src={Trash} mini size="14" />
|
||||||
Deleted
|
Deleted
|
||||||
</Badge>
|
</Badge>
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import { getClient } from '$lib/lemmy'
|
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
import { Color } from '$lib/ui/colors.js'
|
|
||||||
import type { Post } from 'lemmy-js-client'
|
import type { Post } from 'lemmy-js-client'
|
||||||
import {
|
import {
|
||||||
|
ArrowDown,
|
||||||
ArrowDownCircle,
|
ArrowDownCircle,
|
||||||
|
ArrowUp,
|
||||||
ArrowUpCircle,
|
ArrowUpCircle,
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
ChevronUp,
|
ChevronUp,
|
||||||
@@ -13,10 +13,12 @@
|
|||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import { vote as voteItem } from '$lib/lemmy/contentview.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 post: Post
|
||||||
export let vote: number = 0
|
export let vote: number = 0
|
||||||
|
export let upvotes: number = 0
|
||||||
|
export let downvotes: number = 0
|
||||||
export let score: number
|
export let score: number
|
||||||
|
|
||||||
const voteColor = (vote: number) =>
|
const voteColor = (vote: number) =>
|
||||||
@@ -66,42 +68,55 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div
|
<Popover targetClass="h-8" openOnHover>
|
||||||
class="flex items-center text-sm gap-1 rounded-md border border-slate-200
|
<div
|
||||||
dark:border-zinc-700 px-1 h-full duration-200 dark:bg-zinc-900"
|
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"
|
||||||
<Button
|
slot="target"
|
||||||
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
|
||||||
</Button>
|
aria-label="Upvote"
|
||||||
<span
|
class={vote == 1 ? voteColor(vote) : ''}
|
||||||
class="font-medium transition-colors duration-200 {voteColor(vote)}"
|
on:click={async () => {
|
||||||
>
|
if (!$profile?.jwt) return
|
||||||
<FormattedNumber number={score} />
|
score = await voteItem(post, vote == 1 ? 0 : 1, $profile.jwt)
|
||||||
</span>
|
vote = vote == 1 ? 0 : 1
|
||||||
<Button
|
}}
|
||||||
aria-label="Downvote"
|
size="square-sm"
|
||||||
class={vote == -1 ? voteColor(vote) : ''}
|
color="tertiary"
|
||||||
on:click={async () => {
|
alignment="center"
|
||||||
if (!$profile?.jwt) return
|
>
|
||||||
score = await voteItem(post, vote == -1 ? 0 : -1, $profile.jwt)
|
<Icon src={ChevronUp} mini size="18" />
|
||||||
vote = vote == -1 ? 0 : -1
|
</Button>
|
||||||
}}
|
<span
|
||||||
size="square-sm"
|
class="font-medium transition-colors duration-200 {voteColor(vote)}"
|
||||||
color="tertiary"
|
>
|
||||||
>
|
<FormattedNumber number={score} />
|
||||||
<Icon src={ChevronDown} mini size="18" />
|
</span>
|
||||||
</Button>
|
<Button
|
||||||
</div>
|
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}
|
{/if}
|
||||||
</slot>
|
</slot>
|
||||||
@@ -2977,10 +2977,10 @@ mlly@^1.2.0, mlly@^1.4.0:
|
|||||||
pkg-types "^1.0.3"
|
pkg-types "^1.0.3"
|
||||||
ufo "^1.1.2"
|
ufo "^1.1.2"
|
||||||
|
|
||||||
mono-svelte@^0.2.0:
|
mono-svelte@^0.2.2:
|
||||||
version "0.2.0"
|
version "0.2.2"
|
||||||
resolved "https://registry.yarnpkg.com/mono-svelte/-/mono-svelte-0.2.0.tgz#08332d6d356f51c19a4f709d0f69e24b0a425195"
|
resolved "https://registry.yarnpkg.com/mono-svelte/-/mono-svelte-0.2.2.tgz#a7414fa09c7cae03539397e6b3a75b3db16e9fe2"
|
||||||
integrity sha512-gq8z2B1P9kAMd9zwC+CNqEamnO7GWb2KjZsfEzul8kp2uu9kn+Ex+gV+itSYMg7pTcDBG8Rl/di0zaHZbqrm8Q==
|
integrity sha512-SNUAFT4WvexJyqKz31tumsA+/uedzElewC/fvqfPEN03GvRk6Vz7IB8MIkBFQ2Zs2tJ1kkVicW+TAlL2VeYO2A==
|
||||||
|
|
||||||
mri@^1.1.0:
|
mri@^1.1.0:
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
|
|||||||
Reference in new issue
Block a user