impr: you know im not sure if people actually read these. so i can put anything i want

This commit is contained in:
Xylight committed 2025-09-19 16:39:59 -07:00
1 parent 252643b5ed
commit 1a12533fa8
3 files changed
+85 -61

No files matched your search

@@ -17,7 +17,6 @@
ChatBubbleOvalLeft, ChatBubbleOvalLeft,
EllipsisHorizontal, EllipsisHorizontal,
Flag, Flag,
Icon,
PencilSquare, PencilSquare,
Share, Share,
Trash, Trash,
@@ -49,17 +48,17 @@
upvotes={comment.counts.upvotes} upvotes={comment.counts.upvotes}
downvotes={comment.counts.downvotes} downvotes={comment.counts.downvotes}
vote={comment.my_vote} vote={comment.my_vote}
commentId={comment.comment.id} comment={comment.comment}
/> />
<Button <Button
color="tertiary" color="tertiary"
rounding="pill" rounding="pill"
size="sm" size="sm"
class="text-slate-500 dark:text-zinc-400" class="text-slate-500 dark:text-zinc-400 gap-1!"
onclick={() => (replying = !replying)} onclick={() => (replying = !replying)}
disabled={comment.post.locked || disabled || !profile.current.jwt} disabled={comment.post.locked || disabled || !profile.current.jwt}
icon={ChatBubbleOvalLeft}
> >
<Icon src={ChatBubbleOvalLeft} size="15" micro />
{$t('comment.reply')} {$t('comment.reply')}
</Button> </Button>
{#if profile.current?.user && (amMod(profile.current?.user, comment.community) || isAdmin(profile.current.user))} {#if profile.current?.user && (amMod(profile.current?.user, comment.community) || isAdmin(profile.current.user))}
@@ -1,27 +1,30 @@
<script lang="ts"> <script lang="ts">
import { profile } from '$lib/auth.svelte.js' import { profile } from '$lib/auth.svelte.js'
import { site } from '$lib/client/lemmy.svelte'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte' import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { t } from '$lib/i18n/translations' import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/client/lemmy.svelte' import { errorMessage } from '$lib/lemmy/error'
import { settings } from '$lib/settings.svelte'
import { buttonColor, toast } from 'mono-svelte' import { buttonColor, toast } from 'mono-svelte'
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons' import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
import { backOut } from 'svelte/easing' import { backOut } from 'svelte/easing'
import { fly } from 'svelte/transition' import { fly } from 'svelte/transition'
import { shouldShowVoteColor } from '../post/PostVote.svelte' import { shouldShowVoteColor } from '../post/PostVote.svelte'
import { settings } from '$lib/settings.svelte' import { vote as voteItem } from '$lib/lemmy/contentview'
import type { Comment } from '$lib/client/types'
interface Props { interface Props {
vote?: number vote?: number
upvotes: number upvotes: number
downvotes: number downvotes: number
commentId: number comment: Comment
} }
let { let {
vote = $bindable(0), vote = $bindable(0),
upvotes = $bindable(), upvotes = $bindable(),
downvotes = $bindable(), downvotes = $bindable(),
commentId, comment,
}: Props = $props() }: Props = $props()
const castVote = async (newVote: number) => { const castVote = async (newVote: number) => {
@@ -30,12 +33,31 @@
return return
} }
switch (vote ?? 0) {
case 0:
// nothing was removed
if (newVote == 1) upvotes++
else downvotes++
break
case 1:
// removed an upvote
upvotes--
if (newVote == -1) downvotes++
break
case -1:
// removed a downvote
downvotes--
if (newVote == 1) upvotes++
break
}
vote = newVote vote = newVote
const res = await getClient().likeComment({
comment_id: commentId, voteItem(comment, newVote)
score: vote, .then((res) => ({ upvotes, downvotes } = res))
}) .catch((e) => {
;({ upvotes, downvotes } = res.comment_view.counts) toast({ content: errorMessage(e), type: 'error' })
})
} }
let voteRatio = $derived( let voteRatio = $derived(
@@ -43,6 +65,51 @@
) )
</script> </script>
{#snippet voteButton(
votes: number,
target: 'upvote' | 'downvote',
vote?: number,
)}
{@const targetNum = target == 'upvote' ? 1 : -1}
<button
onclick={() => castVote(vote == targetNum ? 0 : targetNum)}
class={[
'flex items-center gap-0.5 transition-colors relative cursor-pointer h-full p-1.5',
'first:rounded-l-3xl last:rounded-r-3xl',
'last:flex-row-reverse',
vote == targetNum
? shouldShowVoteColor(
vote,
target == 'upvote' ? 'upvotes' : 'downvotes',
)
: 'hover:bg-slate-100 dark:hover:bg-zinc-800',
]}
aria-pressed={vote == targetNum}
aria-label={$t(
target == 'upvote'
? 'post.actions.vote.upvote'
: 'post.actions.vote.downvote',
)}
>
<Icon src={target == 'upvote' ? ChevronUp : ChevronDown} size="18" micro />
<div class="grid text-sm z-20">
{#key votes}
<span
style="grid-column: 1; grid-row: 1;"
in:fly={{ duration: 400, y: -10, easing: backOut }}
out:fly={{ duration: 400, y: 10, easing: backOut }}
aria-label={$t(
target == 'upvote' ? 'aria.vote.upvotes' : 'aria.vote.downvotes',
{ default: votes },
)}
>
<FormattedNumber number={votes ?? 0} />
</span>
{/key}
</div>
</button>
{/snippet}
<div <div
class={[ class={[
'h-full relative 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',
@@ -51,53 +118,11 @@
]} ]}
style="--vote-ratio: {voteRatio}%;" style="--vote-ratio: {voteRatio}%;"
> >
<button {@render voteButton(upvotes, 'upvote', vote)}
onclick={() => castVote(vote == 1 ? 0 : 1)} <div class="h-full p-0! border-l border-slate-200 dark:border-zinc-800"></div>
class={[ {#if site.data?.site_view.local_site.enable_downvotes ?? true}
'flex items-center gap-0.5 transition-colors px-1.5 h-full cursor-pointer', {@render voteButton(downvotes, 'downvote', vote)}
vote == 1 {/if}
? shouldShowVoteColor(vote, 'upvotes')
: 'hover:bg-slate-100 dark:hover:bg-zinc-800',
]}
>
<Icon src={ChevronUp} size="18" mini />
<span class="grid text-sm">
{#key upvotes}
<span
style="grid-column: 1; grid-row: 1;"
in:fly={{ duration: 400, y: -10, easing: backOut }}
out:fly={{ duration: 400, y: 10, easing: backOut }}
>
<FormattedNumber number={upvotes} />
</span>
{/key}
</span>
</button>
<div
class="border-l h-full w-0 p-0! border-slate-200 dark:border-zinc-800"
></div>
<button
onclick={() => castVote(vote == -1 ? 0 : -1)}
class={[
'flex flex-row-reverse items-center gap-0.5 transition-colors px-1.5 h-full cursor-pointer',
vote == -1
? shouldShowVoteColor(vote, 'downvotes')
: 'hover:bg-slate-100 dark:hover:bg-zinc-800',
]}
>
<Icon src={ChevronDown} size="18" mini />
<span class="grid text-sm">
{#key downvotes}
<span
style="grid-column: 1; grid-row: 1;"
in:fly={{ duration: 400, y: -10, easing: backOut }}
out:fly={{ duration: 400, y: 10, easing: backOut }}
>
<FormattedNumber number={downvotes} />
</span>
{/key}
</span>
</button>
</div> </div>
<style> <style>
+1 -1
View File
@@ -46,7 +46,7 @@
</div> </div>
{/if} {/if}
<div <div
class="inset-0 -z-10 opacity-0 absolute bg-slate-200 dark:bg-zinc-900 rounded-full class="inset-0 -z-10 opacity-0 absolute bg-slate-200/50 dark:bg-zinc-900/50 rounded-full
group-hover:opacity-100 group-hover:-inset-1 group-hover:-inset-x-2 transition-all" group-hover:opacity-100 group-hover:-inset-1 group-hover:-inset-x-2 transition-all"
></div> ></div>
</div> </div>