Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

comments with background container (#410)

PickleNik9caaf5f3c3d1
diff --git a/apps/web/src/app/challenge/_components/comments/comment-input.tsx b/apps/web/src/app/challenge/_components/comments/comment-input.tsx
index 109471c3..40271976 100644
--- a/apps/web/src/app/challenge/_components/comments/comment-input.tsx
+++ b/apps/web/src/app/challenge/_components/comments/comment-input.tsx
@@ -46,7 +46,7 @@ export function CommentInput({ mode, onCancel, onChange, value, placeholder, onS
};
return (
- <div className="bg-background/90 flex flex-col rounded-xl rounded-br-lg bg-neutral-100 backdrop-blur-sm dark:border-zinc-700 dark:bg-zinc-700/90">
+ <div className="flex flex-col rounded-xl rounded-br-lg bg-neutral-100 backdrop-blur-sm dark:border-zinc-700 dark:bg-zinc-700/90">
{commentMode === 'editor' && (
<Textarea
autoFocus
diff --git a/apps/web/src/app/challenge/_components/comments/comment.tsx b/apps/web/src/app/challenge/_components/comments/comment.tsx
index 5b41ab36..daa49933 100644
--- a/apps/web/src/app/challenge/_components/comments/comment.tsx
+++ b/apps/web/src/app/challenge/_components/comments/comment.tsx
@@ -106,10 +106,24 @@ export function Comment({ comment, readonly = false, rootId, type, queryKey }: C
const toggleIsReplying = () => setIsReplying(!isReplying);
return (
- <div className="flex flex-col p-2">
+ <div className="flex flex-col px-2 py-1">
<SingleComment comment={comment} onClickReply={toggleIsReplying} readonly={readonly} />
+ {comment._count.replies > 0 && (
+ <button
+ className="z-50 ml-2 mt-1 flex cursor-pointer items-center gap-1 text-neutral-500 duration-200 hover:text-neutral-400 dark:text-neutral-400 dark:hover:text-neutral-300"
+ onClick={toggleReplies}
+ >
+ {showReplies ? <ChevronDown className="h-4 w-4" /> : <ChevronUp className="h-4 w-4" />}
+
+ <div className="text-xs">
+ {comment._count.replies === 1 ? '1 reply' : `${comment._count.replies} replies`}
+ </div>
+ </button>
+ )}
+
{isReplying ? (
- <div className="pb-2 pl-6">
+ <div className="relative mt-2 pb-2 pl-8">
+ <Reply className="absolute left-2 top-2 h-4 w-4 opacity-50" />
<CommentInput
mode="edit"
onCancel={() => {
@@ -124,19 +138,9 @@ export function Comment({ comment, readonly = false, rootId, type, queryKey }: C
/>
</div>
) : null}
- {comment._count.replies > 0 && (
- <button
- className="flex cursor-pointer items-center gap-1 text-neutral-500 duration-200 hover:text-neutral-400 dark:text-neutral-400 dark:hover:text-neutral-300"
- onClick={toggleReplies}
- >
- {showReplies ? <ChevronDown size={18} /> : <ChevronUp size={18} />}
- <div className="text-xs">
- {comment._count.replies === 1 ? '1 reply' : `${comment._count.replies} replies`}
- </div>
- </button>
- )}
+
{showReplies ? (
- <div className="flex flex-col gap-0.5 p-2 pl-6 pr-0">
+ <div className="-mt-1 flex flex-col gap-1 p-2 pb-8 pl-8 pr-0">
{data?.pages.flatMap((page) =>
page.comments.map((reply) => (
// this is a reply
@@ -145,6 +149,7 @@ export function Comment({ comment, readonly = false, rootId, type, queryKey }: C
)}
</div>
) : null}
+
{!isFetching && showReplies && data?.pages.at(-1)?.hasMore ? (
<button
className="flex cursor-pointer items-center gap-1 pl-6 text-xs text-neutral-500 duration-200 hover:text-neutral-400 dark:text-neutral-400 dark:hover:text-neutral-300"
@@ -221,7 +226,7 @@ function SingleComment({
const isAuthor = loggedinUser.data?.user.id === comment.user.id;
return (
- <>
+ <div className="relative rounded-xl bg-zinc-200 p-2 pl-3 dark:bg-zinc-600/30">
<div className="flex items-start justify-between gap-4 pr-[0.4rem]">
<div className="flex items-center gap-1">
<UserBadge username={comment.user.name ?? ''} linkComponent={Link} />
@@ -236,10 +241,10 @@ function SingleComment({
</TooltipContent>
</Tooltip>
</div>
- <div className="to-200% my-auto h-[1px] w-full bg-zinc-300 dark:bg-zinc-600" />
<div className="my-auto flex items-center gap-4">
{!readonly && (
<>
+ <Reply className="absolute -left-6 h-4 w-4 opacity-50" />
<div
className="flex cursor-pointer items-center gap-1 text-neutral-500 duration-200 hover:text-neutral-400 dark:text-neutral-400 dark:hover:text-neutral-300"
onClick={() => {
@@ -286,26 +291,28 @@ function SingleComment({
)}
</div>
</div>
- <div>
- {!isEditing && <ExpandableContent content={comment.text} />}
- {isEditing ? (
- <div className="my-2">
- <CommentInput
- mode="edit"
- onCancel={() => {
- setIsEditing(false);
- }}
- onChange={setText}
- onSubmit={async () => {
- await updateChallengeComment();
- setIsEditing(false);
- }}
- value={text}
- />
- </div>
- ) : null}
- </div>
- </>
+ {!isEditing && (
+ <div className="-mb-1">
+ <ExpandableContent content={comment.text} />
+ </div>
+ )}
+ {isEditing ? (
+ <div className="-mx-2 -mb-2">
+ <CommentInput
+ mode="edit"
+ onCancel={() => {
+ setIsEditing(false);
+ }}
+ onChange={setText}
+ onSubmit={async () => {
+ await updateChallengeComment();
+ setIsEditing(false);
+ }}
+ value={text}
+ />
+ </div>
+ ) : null}
+ </div>
);
}
diff --git a/apps/web/src/app/challenge/_components/comments/index.tsx b/apps/web/src/app/challenge/_components/comments/index.tsx
index 6d0badb1..bc586914 100644
--- a/apps/web/src/app/challenge/_components/comments/index.tsx
+++ b/apps/web/src/app/challenge/_components/comments/index.tsx
@@ -108,7 +108,7 @@ export function Comments({ rootId, type }: Props) {
)}
ref={commentContainerRef}
>
- <div className="m-2 mt-0">
+ <div className="m-2 mb-4 mt-0">
<CommentInput
mode="create"
onChange={setText}
diff --git a/apps/web/src/components/ui/markdown.tsx b/apps/web/src/components/ui/markdown.tsx
index e31830e8..8740f363 100644
--- a/apps/web/src/components/ui/markdown.tsx
+++ b/apps/web/src/components/ui/markdown.tsx
@@ -59,7 +59,9 @@ export function Markdown({ children, className }: { children: string; className?
h3: ({ className, ...props }) => (
<h3 className={clsx(className, 'mb-2 pb-2 text-xl font-bold')} {...props} />
),
- p: ({ className, ...props }) => <p className={clsx(className, 'mb-4')} {...props} />,
+ p: ({ className, ...props }) => (
+ <p className={clsx(className, 'mb-4 last-of-type:mb-1.5')} {...props} />
+ ),
code({ inline, className, children, style: _, ...props }) {
const match = /language-(\w+)/.exec(className || '');
return !inline && match ? (