|
3 | 3 | import { Avatar } from '$lib/ui'; |
4 | 4 | import { cn } from '$lib/utils'; |
5 | 5 | import type { HTMLAttributes } from 'svelte/elements'; |
6 | | - import CommentComponent from './Comment.svelte'; |
7 | 6 | import type { CommentType } from '$lib/types'; |
8 | 7 |
|
9 | 8 | interface ICommentProps extends HTMLAttributes<HTMLElement> { |
10 | 9 | comment: CommentType; |
11 | | - handleReply: (id: string) => void; |
| 10 | + handleReply: () => void; |
12 | 11 | } |
13 | 12 |
|
14 | 13 | let visibleReplies = $state(2); |
|
70 | 69 | /> |
71 | 70 | </button> |
72 | 71 | <span class="bg-black-600 inline-block h-1 w-1 rounded-full"></span> |
73 | | - <button onclick={() => handleReply(comment.commentId)} class="text-black-600 font-semibold" |
| 72 | + <button onclick={handleReply} class="text-black-600 font-semibold" |
74 | 73 | >Reply</button |
75 | 74 | > |
76 | 75 | <span class="bg-black-600 inline-block h-1 w-1 rounded-full"></span> |
|
80 | 79 | <ul class="ms-12 mt-4 space-y-2"> |
81 | 80 | {#each comment.replies.slice(0, visibleReplies) as reply} |
82 | 81 | <li> |
83 | | - <CommentComponent comment={reply} {handleReply} /> |
| 82 | + <div class="align-start flex gap-2"> |
| 83 | + <Avatar src={reply.userImgSrc} size="sm" /> |
| 84 | + <div> |
| 85 | + <h3 class="font-semibold text-black">{reply.name}</h3> |
| 86 | + <p class="text-black-600 mt-0.5">{reply.comment}</p> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + <div class="ms-12 mt-2 flex items-center gap-2"> |
| 90 | + <button |
| 91 | + onclick={() => { |
| 92 | + if (!reply.isUpVoted) { |
| 93 | + reply.upVotes++; |
| 94 | + reply.isUpVoted = true; |
| 95 | + reply.isDownVoted = false; |
| 96 | + } |
| 97 | + }} |
| 98 | + > |
| 99 | + <Like |
| 100 | + size="18px" |
| 101 | + color={reply.isUpVoted |
| 102 | + ? 'var(--color-brand-burnt-orange)' |
| 103 | + : 'var(--color-black-600)'} |
| 104 | + fill={reply.isUpVoted |
| 105 | + ? 'var(--color-brand-burnt-orange)' |
| 106 | + : 'var(--color-black-600)'} |
| 107 | + /> |
| 108 | + </button> |
| 109 | + <p class="text-black-600 font-semibold">{reply.upVotes}</p> |
| 110 | + <button |
| 111 | + onclick={() => { |
| 112 | + if (!reply.isDownVoted) { |
| 113 | + reply.upVotes--; |
| 114 | + reply.isDownVoted = true; |
| 115 | + reply.isUpVoted = false; |
| 116 | + } |
| 117 | + }} |
| 118 | + > |
| 119 | + <Like |
| 120 | + size="18px" |
| 121 | + color={reply.isDownVoted |
| 122 | + ? 'var(--color-brand-burnt-orange)' |
| 123 | + : 'var(--color-black-600)'} |
| 124 | + fill={reply.isDownVoted |
| 125 | + ? 'var(--color-brand-burnt-orange)' |
| 126 | + : 'var(--color-black-600)'} |
| 127 | + class="rotate-180" |
| 128 | + /> |
| 129 | + </button> |
| 130 | + <span class="bg-black-600 inline-block h-1 w-1 rounded-full"></span> |
| 131 | + <button onclick={handleReply} class="text-black-600 font-semibold" |
| 132 | + >Reply</button |
| 133 | + > |
| 134 | + <span class="bg-black-600 inline-block h-1 w-1 rounded-full"></span> |
| 135 | + <p class="text-black-600">{reply.time}</p> |
| 136 | + </div> |
84 | 137 | </li> |
85 | 138 | {/each} |
86 | 139 | {#if comment.replies.length > visibleReplies} |
|
0 commit comments