misc: Tweak comment vote design
This commit is contained in:
1 parent
563f1fce43
commit
d3ff9e37dc
12 files changed
+256
-94
No files matched your search
@@ -60,17 +60,10 @@
|
||||
|
||||
<slot {upvote} {downvote} {vote} {score}>
|
||||
<div
|
||||
class="{Color.border} text-sm rounded-md flex flex-row items-center px-1.5
|
||||
class="{Color.border} text-sm gap-0.5 rounded-md flex flex-row items-center px-1
|
||||
py-0.5
|
||||
transition-colors cursor-pointer
|
||||
{// upvote
|
||||
vote == 1
|
||||
? 'bg-orange-600/20 text-orange-500'
|
||||
: // downvote
|
||||
vote == -1
|
||||
? 'bg-blue-600/40 text-blue-400'
|
||||
: // no vote
|
||||
'bg-slate-100 dark:bg-zinc-800 hover:bg-slate-200 dark:hover:bg-zinc-700'}"
|
||||
transition-colors cursor-pointer bg-slate-100 dark:bg-zinc-800
|
||||
hover:bg-slate-200 dark:hover:bg-zinc-700"
|
||||
>
|
||||
<button aria-label="Upvote" class="p-0.5 px-1" on:click={upvote}>
|
||||
<Icon src={ChevronUp} mini width={20} height={20} />
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
ArrowDown,
|
||||
ArrowUp,
|
||||
ChatBubbleOvalLeft,
|
||||
ChevronDown,
|
||||
ChevronUp,
|
||||
Icon,
|
||||
Minus,
|
||||
Plus,
|
||||
@@ -17,6 +19,8 @@
|
||||
import { page } from '$app/stores'
|
||||
import UserLink from '$lib/components/user/UserLink.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import CommentVote from '$lib/components/lemmy/comment/CommentVote.svelte'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
|
||||
export let node: CommentNodeI
|
||||
export let postId: number
|
||||
@@ -24,59 +28,6 @@
|
||||
|
||||
export let open = true
|
||||
export let replying = false
|
||||
|
||||
let score = node.comment_view.counts.score
|
||||
let vote = node.comment_view.my_vote ?? 0
|
||||
|
||||
async function upvote() {
|
||||
if (!$authData) return
|
||||
|
||||
const upvoted = node.comment_view.my_vote == 1
|
||||
|
||||
if (vote == -1) {
|
||||
score += 2
|
||||
} else if (vote == 1) {
|
||||
score -= 1
|
||||
} else if (vote == 0) {
|
||||
score += 1
|
||||
}
|
||||
|
||||
vote = Number(!upvoted)
|
||||
node.comment_view.my_vote = Number(!upvoted)
|
||||
|
||||
await getClient()
|
||||
.likeComment({
|
||||
score: upvoted ? 0 : 1,
|
||||
auth: $authData.token,
|
||||
comment_id: node.comment_view.comment.id,
|
||||
})
|
||||
.catch((_) => undefined)
|
||||
}
|
||||
|
||||
async function downvote() {
|
||||
if (!$authData) return
|
||||
|
||||
const upvoted = node.comment_view.my_vote == -1
|
||||
|
||||
if (vote == -1) {
|
||||
score += 1
|
||||
} else if (vote == 1) {
|
||||
score -= 2
|
||||
} else if (vote == 0) {
|
||||
score -= 1
|
||||
}
|
||||
|
||||
vote = -Number(!upvoted)
|
||||
node.comment_view.my_vote = -Number(!upvoted)
|
||||
|
||||
await getClient()
|
||||
.likeComment({
|
||||
score: upvoted ? 0 : -1,
|
||||
auth: $authData.token,
|
||||
comment_id: node.comment_view.comment.id,
|
||||
})
|
||||
.catch((_) => undefined)
|
||||
}
|
||||
</script>
|
||||
|
||||
<li
|
||||
@@ -123,31 +74,15 @@
|
||||
<div class="max-w-full break-words text-sm leading-6">
|
||||
<Markdown source={node.comment_view.comment.content} />
|
||||
</div>
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
<div class="flex flex-row items-center">
|
||||
<button
|
||||
on:click={upvote}
|
||||
class="pr-1.5 {node.comment_view.my_vote == 1
|
||||
? 'text-orange-500'
|
||||
: ''}"
|
||||
>
|
||||
<Icon src={ArrowUp} width={16} mini />
|
||||
</button>
|
||||
<span class="text-sm font-medium">
|
||||
{score}
|
||||
</span>
|
||||
<button
|
||||
on:click={downvote}
|
||||
class="pl-1.5 {node.comment_view.my_vote == -1
|
||||
? 'text-blue-500'
|
||||
: ''}"
|
||||
>
|
||||
<Icon src={ArrowDown} width={16} mini />
|
||||
</button>
|
||||
</div>
|
||||
<div class="flex flex-row gap-2 items-center mt-1">
|
||||
<CommentVote
|
||||
bind:score={node.comment_view.counts.score}
|
||||
bind:vote={node.comment_view.my_vote}
|
||||
commentId={node.comment_view.comment.id}
|
||||
/>
|
||||
<button
|
||||
class="flex flex-row gap-1 items-center transition-colors px-2 py-1
|
||||
rounded-md {Color.secondary}"
|
||||
class="{Color.borderDark} px-2 py-1 flex flex-row items-center gap-1
|
||||
rounded-md transition-colors"
|
||||
on:click={() => (replying = !replying)}
|
||||
>
|
||||
<Icon src={ChatBubbleOvalLeft} width={16} height={16} mini />
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<script lang="ts">
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
|
||||
export let vote: number = 0
|
||||
export let score: number
|
||||
export let commentId: number
|
||||
|
||||
async function upvote() {
|
||||
if (!$authData) return
|
||||
|
||||
const upvoted = vote == 1
|
||||
|
||||
if (vote == -1) {
|
||||
score += 2
|
||||
} else if (vote == 1) {
|
||||
score -= 1
|
||||
} else if (vote == 0) {
|
||||
score += 1
|
||||
}
|
||||
|
||||
vote = Number(!upvoted)
|
||||
|
||||
await getClient()
|
||||
.likeComment({
|
||||
score: upvoted ? 0 : 1,
|
||||
auth: $authData.token,
|
||||
comment_id: commentId,
|
||||
})
|
||||
.catch((_) => undefined)
|
||||
}
|
||||
|
||||
async function downvote() {
|
||||
if (!$authData) return
|
||||
|
||||
const upvoted = vote == -1
|
||||
|
||||
if (vote == -1) {
|
||||
score += 1
|
||||
} else if (vote == 1) {
|
||||
score -= 2
|
||||
} else if (vote == 0) {
|
||||
score -= 1
|
||||
}
|
||||
|
||||
vote = -Number(!upvoted)
|
||||
|
||||
await getClient()
|
||||
.likeComment({
|
||||
score: upvoted ? 0 : -1,
|
||||
auth: $authData.token,
|
||||
comment_id: commentId,
|
||||
})
|
||||
.catch((_) => undefined)
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="flex flex-row items-center rounded-md px-2 py-0.5 transition-colors
|
||||
cursor-pointer {Color.borderDark}"
|
||||
>
|
||||
<button
|
||||
on:click={upvote}
|
||||
class="pr-1.5 {vote == 1 ? 'text-orange-500' : ''}"
|
||||
aria-label="Upvote"
|
||||
>
|
||||
<Icon src={ChevronUp} width={19} mini />
|
||||
</button>
|
||||
<span class="text-sm">
|
||||
{score}
|
||||
</span>
|
||||
<button
|
||||
on:click={downvote}
|
||||
class="pl-1.5 {vote == -1 ? 'text-blue-500' : ''}"
|
||||
aria-label="Downvote"
|
||||
>
|
||||
<Icon src={ChevronDown} width={19} mini />
|
||||
</button>
|
||||
</div>
|
||||
@@ -67,11 +67,12 @@
|
||||
<svelte:self {post} nodes={node.children} isParent={false} />
|
||||
{/if}
|
||||
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
|
||||
<div class="m-1">
|
||||
<div class="m-1 w-full max-w-[9rem]">
|
||||
<Button
|
||||
loading={loadingChildren}
|
||||
disabled={loadingChildren}
|
||||
on:click={() => fetchChildren(node)}
|
||||
large
|
||||
>
|
||||
<Icon src={ChevronDown} width={16} mini />
|
||||
Load {node.comment_view.counts.child_count} more
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
</script>
|
||||
|
||||
<img
|
||||
src={`${url}?format=webp&thumbnail=${width * 2}` ??
|
||||
`https://api.dicebear.com/6.x/initials/svg?seed=${alt}`}
|
||||
src="{url ??
|
||||
`https://api.dicebear.com/6.x/initials/svg?seed=${alt}`}?format=webp&thumbnail={width *
|
||||
2}"
|
||||
{alt}
|
||||
{width}
|
||||
loading="lazy"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
import {
|
||||
ArrowLeftOnRectangle,
|
||||
ArrowRightOnRectangle,
|
||||
Beaker,
|
||||
Cog6Tooth,
|
||||
GlobeAlt,
|
||||
Icon,
|
||||
@@ -92,6 +93,10 @@
|
||||
<span class="text-xs opacity-80 text-left mx-4 my-2">
|
||||
{$user ? $user.person_view.person.name : 'Profile'}
|
||||
</span>
|
||||
<MenuButton link href="/experiments">
|
||||
<Icon src={Beaker} mini width={16} />
|
||||
Experiments
|
||||
</MenuButton>
|
||||
{#if !$user || !$authData}
|
||||
<MenuButton link href="/login">
|
||||
<Icon src={ArrowLeftOnRectangle} mini width={16} /> Log in
|
||||
|
||||
Reference in new issue
Block a user