Skip to content

Commit 28c1cad

Browse files
committed
Improve comments layout
1 parent b8f3d6d commit 28c1cad

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

src/components/Comments.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ const SingleComment: React.FC<CommentProps> = ({ comment, postAuthor }) => {
5454
if (!comment?.body_html) return null;
5555

5656
return (
57-
<div className="prose text-gray-500 prose-sm prose-headings:font-normal prose-headings:text-xl mx-auto w-full mb-4 hover:bg-slate-100 lg:hover:bg-transparent dark:hover:bg-slate-800 lg:dark:hover:bg-transparent px-1 rounded-md">
58-
<div className="flex justify-between items-center w-full max-w-[100vw]">
59-
<div className="flex items-center space-x-2 overflow-hidden">
57+
<div className="bg-slate-200 dark:bg-neutral-800 text-gray-800 dark:text-gray-100 rounded-lg px-2 pt-1 mb-2">
58+
<div className="flex justify-between items-center w-full">
59+
<div className="flex items-center flex-wrap gap-2 overflow-hidden">
6060
<a href={`/user/${comment.author}`} className="flex items-center space-x-1">
61-
<h3 className="font-semibold text-sm text-blue-400 whitespace-nowrap">{comment.author}</h3>
61+
<h3 className="font-semibold text-sm text-blue-500 whitespace-nowrap hover:underline">{comment.author}</h3>
6262
{comment?.distinguished === "moderator" && (
63-
<p className="px-0.5 text-sm font-semibold text-green-500">{"MOD"}</p>
63+
<span className="text-green-500 text-xs font-semibold">MOD</span>
6464
)}
6565
</a>
6666
{comment.author === postAuthor && (
67-
<span className="whitespace-nowrap rounded-md bg-gray-100 dark:bg-slate-700 p-0.5 font-semibold text-xs text-blue-700">
67+
<span className="rounded bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300 px-1 py-0.5 text-xs font-semibold">
6868
OP
6969
</span>
7070
)}
@@ -76,27 +76,32 @@ const SingleComment: React.FC<CommentProps> = ({ comment, postAuthor }) => {
7676
<CreatedEditedLabel created={comment.created} edited={comment.edited} />
7777
</div>
7878
</div>
79-
<BodyHtml body_html={comment.body_html} />
80-
<div className="text-gray-500 text-xs mt-2 dark:text-slate-200 flex space-x-1">
79+
80+
<div className="mt-2">
81+
<BodyHtml body_html={comment.body_html} />
82+
</div>
83+
84+
<div className="text-gray-600 dark:text-gray-300 text-xs mt-2 flex items-center space-x-1">
8185
<UpvoteIcon />
8286
<span className="font-medium">{comment.score.toLocaleString("en-US")}</span>
83-
<span className="font-base">
84-
{comment.score === 1 ? "upvote" : "upvotes"}
85-
</span>
87+
<span>{comment.score === 1 ? "upvote" : "upvotes"}</span>
8688
</div>
89+
8790
{comment.replies?.data?.children?.length > 0 && (
88-
<button className="dark:text-gray-300 text-xs mt-2" onClick={() => setShowReplies(!showReplies)}>
91+
<button
92+
className="text-xs text-blue-500 mt-2 focus:outline-none"
93+
onClick={() => setShowReplies(!showReplies)}
94+
>
8995
{showReplies ? "➖ Hide Replies" : "➕ Show Replies"}
9096
</button>
9197
)}
98+
9299
{showReplies && (
93-
<div className="relative border-l-[0.5px] border-gray-700 pl-1 lg:pl-3 ml-0">
100+
<div className="relative border-l-[0.5px] border-gray-700 pl-1 lg:pl-3 ml-0 mb-2">
94101
{comment.replies?.data?.children?.map((childWrapper: Children2) => {
95102
const child = childWrapper.data;
96103
return child ? (
97-
<div key={child.id} className="mt-4">
98-
<SingleComment comment={child} postAuthor={postAuthor} />
99-
</div>
104+
<SingleComment key={child.id} comment={child} postAuthor={postAuthor} />
100105
) : null;
101106
})}
102107
</div>

src/components/Feed.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ const Feed: React.FC<FeedProps> = memo(({ subreddit, initialTime, initialSort })
237237
{posts.map((post) => (
238238
<div
239239
key={post.id}
240-
className="bg-slate-200 dark:bg-neutral-800 shadow-md rounded-xl p-4 mb-6 w-full mx-auto prose prose-sm text-gray-700 dark:text-gray-300 prose-headings:font-semibold prose-headings:text-xl"
240+
className="bg-slate-200 dark:bg-neutral-800 shadow-md rounded-xl p-2 mb-6 w-full mx-auto prose prose-sm text-gray-700 dark:text-gray-300 prose-headings:font-semibold prose-headings:text-xl"
241241
>
242242
<div>
243243
<div className="flex items-center space-x-2 mb-2">

src/components/Post.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const PostComponent = ({ post }: { post: Post }) => {
2323
return (
2424
<div
2525
key={post.id}
26-
className="bg-slate-200 dark:bg-neutral-800 shadow-md rounded-xl p-4 mb-4 w-full mx-auto prose prose-sm text-gray-700 dark:text-gray-300 prose-headings:font-semibold prose-headings:text-xl overflow-auto"
26+
className="bg-slate-200 dark:bg-neutral-800 shadow-md rounded-xl p-2 mb-4 w-full mx-auto prose prose-sm text-gray-700 dark:text-gray-300 prose-headings:font-semibold prose-headings:text-xl overflow-auto"
2727
>
2828
<div className="flex items-center space-x-2 mb-1">
2929
<a href={`/user/${post.author}`}>

0 commit comments

Comments
 (0)