feat: new vote design

This commit is contained in:
Xyphyn committed 2023-08-14 17:00:54 -07:00
1 parent 6630b89bce
commit bc553804ce
4 files changed
+39 -27

No files matched your search

@@ -18,6 +18,7 @@
import { getClient } from '$lib/lemmy.js' import { getClient } from '$lib/lemmy.js'
import { toast } from '$lib/components/ui/toasts/toasts.js' import { toast } from '$lib/components/ui/toasts/toasts.js'
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
import { slide } from 'svelte/transition'
export let node: CommentNodeI export let node: CommentNodeI
export let postId: number export let postId: number
@@ -62,7 +62,7 @@
const dispatcher = createEventDispatcher<{ edit: CommentView }>() const dispatcher = createEventDispatcher<{ edit: CommentView }>()
</script> </script>
<div class="flex flex-row gap-2 items-center mt-1 h-[26px] relative"> <div class="flex flex-row gap-2 items-center mt-1 h-7 relative">
<CommentVote <CommentVote
bind:score={comment.counts.score} bind:score={comment.counts.score}
bind:vote={comment.my_vote} bind:vote={comment.my_vote}
@@ -80,16 +80,11 @@
{#if $profile?.user && (amMod($profile?.user, comment.community) || isAdmin($profile.user))} {#if $profile?.user && (amMod($profile?.user, comment.community) || isAdmin($profile.user))}
<CommentModerationMenu bind:item={comment} /> <CommentModerationMenu bind:item={comment} />
{/if} {/if}
<Menu <Menu let:toggleOpen class="h-7 top-0 leading-3" alignment="bottom-center">
let:toggleOpen
class="h-[26px] top-0 leading-3"
alignment="bottom-center"
>
<Button <Button
slot="button" slot="button"
color="elevatedLow" color="elevatedLow"
on:click={toggleOpen} on:click={toggleOpen}
size="sm"
class="!p-1" class="!p-1"
aria-label="Comment actions" aria-label="Comment actions"
> >
@@ -113,10 +113,10 @@
<PostVote post={post.post} vote={post.my_vote} score={post.counts.score} /> <PostVote post={post.post} vote={post.my_vote} score={post.counts.score} />
<Button <Button
color="elevated" color="secondary"
size="sm" size="sm"
href="/post/{getInstance()}/{post.post.id}" href="/post/{getInstance()}/{post.post.id}"
class="px-3 h-full" class="px-3 h-full !text-inherit"
> >
<Icon slot="icon" src={ChatBubbleOvalLeft} width={16} height={16} /> <Icon slot="icon" src={ChatBubbleOvalLeft} width={16} height={16} />
<FormattedNumber number={post.counts.comments} /> <FormattedNumber number={post.counts.comments} />
+34 -18
View File
@@ -5,7 +5,13 @@
import { userSettings } from '$lib/settings.js' import { userSettings } from '$lib/settings.js'
import { Color } from '$lib/ui/colors.js' import { Color } from '$lib/ui/colors.js'
import type { Post } from 'lemmy-js-client' import type { Post } from 'lemmy-js-client'
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons' import {
ArrowDownCircle,
ArrowUpCircle,
ChevronDown,
ChevronUp,
Icon,
} from 'svelte-hero-icons'
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
import { slide } from 'svelte/transition' import { slide } from 'svelte/transition'
@@ -64,32 +70,42 @@
}) })
.catch((_) => undefined) .catch((_) => undefined)
} }
const voteColor = (vote: number) =>
vote == 1
? $userSettings.revertColors
? '!text-orange-500'
: '!text-blue-400'
: vote == -1
? $userSettings.revertColors
? '!text-blue-500'
: '!text-red-500'
: ''
</script> </script>
<slot {upvote} {downvote} {vote} {score}> <slot {upvote} {downvote} {vote} {score}>
<div <div class="flex items-center text-sm gap-1 rounded-md border-zinc-700">
class="{Color.border} text-sm gap-0.5 rounded-md flex flex-row items-center <Button
transition-colors cursor-pointer bg-slate-100 dark:bg-zinc-800
hover:bg-slate-200 dark:hover:bg-zinc-700 h-full"
>
<button
aria-label="Upvote" aria-label="Upvote"
class:text-orange-500={vote == 1 && $userSettings.revertColors} class={vote == 1 ? voteColor(vote) : ''}
class:text-blue-500={vote == 1 && !$userSettings.revertColors}
class="py-1 pr-0.5 pl-2"
on:click={upvote} on:click={upvote}
size="square-md"
color="tertiary"
alignment="center"
> >
<Icon src={ChevronUp} mini width={20} height={20} /> <Icon src={ArrowUpCircle} mini={vote == 1} width={20} height={20} />
</button> </Button>
<span class="font-medium {voteColor(vote)}">
<FormattedNumber number={score} /> <FormattedNumber number={score} />
<button </span>
<Button
aria-label="Downvote" aria-label="Downvote"
class:text-blue-500={vote == -1 && $userSettings.revertColors} class={vote == -1 ? voteColor(vote) : ''}
class:text-red-500={vote == -1 && !$userSettings.revertColors}
class="py-1 pl-0.5 pr-2"
on:click={downvote} on:click={downvote}
size="square-md"
color="tertiary"
> >
<Icon src={ChevronDown} mini width={20} height={20} /> <Icon src={ArrowDownCircle} solid={vote == -1} width={20} height={20} />
</button> </Button>
</div> </div>
</slot> </slot>