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
@@ -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
|
||||
|
||||
Reference in new issue
Block a user