Connect, collaborate, and grow with a community of TypeScript developers
ben + trash rebase fixes (#321)
bautistaaab7b920a017ba
diff --git a/prisma/comment.mock.ts b/prisma/comment.mock.tsnew file mode 100644index 00000000..ce1243b3--- /dev/null+++ b/prisma/comment.mock.ts@@ -0,0 +1,14 @@+import { type Prisma } from '@prisma/client';+import { trashId } from './seed';++/**+ *+ * @returns Creates a mock user.+ */+export default function CommentMock(parentId?: number): Prisma.CommentCreateManyInput {+ return {+ text: 'here is a comment',+ userId: trashId,+ parentId: parentId,+ };+}diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex b5f69a9f..234b3a94 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -299,10 +299,12 @@ enum CommentRoot {}model Comment {- id Int @id @default(autoincrement())- text String @db.MediumText- visible Boolean @default(true)- parentId Int?+ id Int @id @default(autoincrement())+ text String @db.MediumText+ visible Boolean @default(true)+ parentId Int?+ parentComment Comment? @relation("reply_comments", fields: [parentId], references: [id], onUpdate: NoAction, onDelete: NoAction)+ replies Comment[] @relation("reply_comments")userId Stringuser User @relation(fields: [userId], references: [id])@@ -321,6 +323,7 @@ model Comment {@@index([rootSolutionId])@@index([rootChallengeId])+ @@index([parentId])@@index([userId])}@@ -355,4 +358,3 @@ model ImageUpload {@@index([userId])}-diff --git a/prisma/seed.ts b/prisma/seed.tsindex 7db0590e..5c5dd2f2 100644--- a/prisma/seed.ts+++ b/prisma/seed.ts@@ -1,7 +1,8 @@import { faker } from '@faker-js/faker';-import { PrismaClient } from '@prisma/client';+import { PrismaClient, type Prisma } from '@prisma/client';import uuidByString from 'uuid-by-string';import { loadChallengesFromTypeChallenge } from './challenges.mock';+import CommentMock from './comment.mock';import UserMock from './user.mock';const prisma = new PrismaClient();@@ -39,7 +40,11 @@ export const trashId = uuidByString('trash');export const gId = uuidByString('g');try {- const someChallenge = await prisma.challenge.findFirst();+ const someChallenge = await prisma.challenge.findFirst({+ where: {+ status: 'ACTIVE',+ },+ });await prisma.user.upsert({where: { id: trashId },@@ -54,14 +59,31 @@ try {},});+ const comments = Array.from({ length: 10 }, () => CommentMock());++ const replies: Prisma.CommentCreateManyInput[] = [];++ const { comment: createdComments } = await prisma.challenge.update({+ where: { id: someChallenge?.id },+ include: {+ comment: true,+ },+ data: {+ comment: {+ create: comments,+ },+ },+ });++ for (const comment of createdComments) {+ replies.push(CommentMock(comment.id), CommentMock(comment.id));+ }+await prisma.challenge.update({where: { id: someChallenge?.id },data: {comment: {- create: Array.from({ length: 50 }, () => ({- text: 'here is a comment',- userId: trashId,- })),+ create: replies,},},});diff --git a/src/app/admin/report/[id]/report.action.ts b/src/app/admin/report/[id]/report.action.tsindex 842093ea..f1806284 100644--- a/src/app/admin/report/[id]/report.action.ts+++ b/src/app/admin/report/[id]/report.action.ts@@ -43,6 +43,11 @@ export async function getReport(idNum: number) {comment: {include: {user: true,+ _count: {+ select: {+ replies: true,+ },+ },rootChallenge: true,rootSolution: true,},diff --git a/src/app/challenge/[id]/page.tsx b/src/app/challenge/[id]/page.tsxindex f3137ab9..3d1abc19 100644--- a/src/app/challenge/[id]/page.tsx+++ b/src/app/challenge/[id]/page.tsx@@ -1,8 +1,8 @@import { notFound } from 'next/navigation';+import { Comments } from '~/components/challenge/comments';import { Description } from '~/components/challenge/description';import { getServerAuthSession } from '~/server/auth';import { getChallengeRouteData } from './getChallengeRouteData';-import { Comments } from '~/components/challenge/comments';interface Props {params: {diff --git a/src/components/challenge/comments/comment-input.tsx b/src/components/challenge/comments/comment-input.tsxindex 8c5ab648..fbd58b00 100644--- a/src/components/challenge/comments/comment-input.tsx+++ b/src/components/challenge/comments/comment-input.tsx@@ -8,15 +8,15 @@ import { ToastAction } from '~/components/ui/toast';import { useToast } from '~/components/ui/use-toast';interface Props {- mode: 'edit' | 'create';+ mode: 'edit' | 'create' | 'reply';onCancel?: () => void;onChange: (text: string) => void;- onKeyDown: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void;value: string;+ placeholder?: string;onSubmit: () => Promise<void>;}-export function CommentInput({ mode, onCancel, onChange, onKeyDown, value, onSubmit }: Props) {+export function CommentInput({ mode, onCancel, onChange, value, placeholder, onSubmit }: Props) {const { data: session } = useSession();const { toast } = useToast();const [commentMode, setCommentMode] = useState<'editor' | 'preview'>('editor');@@ -25,19 +25,40 @@ export function CommentInput({ mode, onCancel, onChange, onKeyDown, value, onSubuseAutosizeTextArea(textAreaRef, value, commentMode);+ const handleEnterKey = async (e: React.KeyboardEvent<HTMLTextAreaElement>) => {+ if (isSubmitting) {+ e.preventDefault();+ return;+ }++ if (e.shiftKey && e.key === 'Enter') {+ e.preventDefault();+ if (!session?.user) {+ toast({+ variant: 'destructive',+ title: 'You need to be logged in to comment.',+ action: <ToastAction altText="Dismiss">Dismiss</ToastAction>,+ });++ return;+ }+ setIsSubmitting(true);+ await onSubmit();+ setIsSubmitting(false);+ }+ };+return (<div className="flex flex-col rounded-xl rounded-br-lg bg-background/90 bg-neutral-100 backdrop-blur-sm dark:border-zinc-700 dark:bg-zinc-700/90">{commentMode === 'editor' && (<Textarea+ autoFocusref={textAreaRef}value={value}onChange={(e) => onChange(e.target.value)}- onKeyDown={(e) => {- if (isSubmitting) return;- onKeyDown(e);- }}+ onKeyDown={handleEnterKey}className="resize-none border-0 px-3 py-2 focus-visible:ring-0 focus-visible:ring-offset-0 md:max-h-[calc(100vh_-_232px)]"- placeholder="Enter your comment here."+ placeholder={placeholder ?? 'Enter your comment here.'}/>)}{commentMode === 'preview' && (@@ -54,7 +75,7 @@ export function CommentInput({ mode, onCancel, onChange, onKeyDown, value, onSub>{commentMode === 'editor' ? 'Preview' : 'Edit'}</Button>- {mode === 'edit' && (+ {mode !== 'create' && (<Button variant="secondary" className="h-8" onClick={() => onCancel?.()}>Cancel</Button>@@ -110,4 +131,4 @@ function useAutosizeTextArea(}// eslint-disable-next-line}, [textAreaRef.current, value, commentMode]);-}+}\ No newline at end of filediff --git a/src/components/challenge/comments/comment.action.ts b/src/components/challenge/comments/comment.action.tsindex f80432e5..2a09f576 100644--- a/src/components/challenge/comments/comment.action.ts+++ b/src/components/challenge/comments/comment.action.ts@@ -37,6 +37,30 @@ export async function addComment(comment: CommentToCreate) {});}+export async function replyComment(comment: CommentToCreate, parentId: number) {+ const session = await getServerAuthSession();++ if (!session?.user.id) return 'unauthorized';+ if (comment.text.length === 0) return 'text_is_empty';+ if (!session?.user.id) return 'unauthorized';+ if (comment.text.length === 0) return 'text_is_empty';++ const { rootId, ...commentToCreate } = {+ ...comment,+ ...(comment.rootType === 'CHALLENGE'+ ? { rootChallengeId: comment.rootId }+ : { rootSolutionId: comment.rootId }),+ };++ return await prisma.comment.create({+ data: {+ ...commentToCreate,+ parentId,+ userId: session.user.id,+ },+ });+}+export async function updateComment(text: string, id: number) {const session = await getServerAuthSession();@@ -85,6 +109,11 @@ export async function getCommentsByChallengeId(id: number) {},include: {user: true,+ _count: {+ select: {+ replies: true,+ },+ },},orderBy: [{diff --git a/src/components/challenge/comments/comment.tsx b/src/components/challenge/comments/comment.tsxindex e93a89ea..10bb0742 100644--- a/src/components/challenge/comments/comment.tsx+++ b/src/components/challenge/comments/comment.tsx@@ -1,27 +1,37 @@'use client';-import { useQueryClient } from '@tanstack/react-query';-import clsx from 'clsx';-import { Pencil, Reply, Share, Trash2 } from 'lucide-react';+import { type CommentRoot } from '@prisma/client';+import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query';+import { ChevronDown, ChevronUp, Pencil, Reply, Share, Trash2 } from 'lucide-react';import { useSession } from 'next-auth/react';import { useEffect, useRef, useState } from 'react';import { z } from 'zod';import ReportDialog from '~/components/report';-import { Markdown } from '~/components/ui/markdown';import { Tooltip, TooltipContent, TooltipTrigger } from '~/components/ui/tooltip';import { toast } from '~/components/ui/use-toast';import { UserBadge } from '~/components/ui/user-badge';import { getRelativeTime } from '~/utils/relativeTime';import { CommentInput } from './comment-input';-import { updateComment, type CommentsByChallengeId } from './comment.action';+import { replyComment, updateComment, type CommentsByChallengeId } from './comment.action';import { CommentDeleteDialog } from './delete';+import { getPaginatedComments } from './getCommentRouteData';+import clsx from 'clsx';+import { Markdown } from '~/components/ui/markdown';-interface CommentProps {+interface SingleCommentProps {comment: CommentsByChallengeId[number];- queryKey?: (string | number)[];readonly?: boolean;+ isReply?: boolean;+ onClickReply?: () => void;+ queryKey?: (string | number)[];+ replyQueryKey?: (string | number)[];}+type CommentProps = SingleCommentProps & {+ rootId: number;+ type: CommentRoot;+};+const commentReportSchema = z.object({spam: z.boolean().optional(),@@ -43,34 +53,122 @@ const commentReportSchema = zexport type CommentReportSchemaType = z.infer<typeof commentReportSchema>;-export const Comment = ({ comment, queryKey, readonly = false }: CommentProps) => {+export const Comment = ({ comment, readonly = false, rootId, type, queryKey }: CommentProps) => {+ const [showReplies, setShowReplies] = useState(false);++ const [isReplying, setIsReplying] = useState(false);+ const [replyText, setReplyText] = useState('');const queryClient = useQueryClient();- const [text, setText] = useState(comment.text);- const [isEditing, setIsEditing] = useState(false);- async function copyPathNotifyUser() {+ const replyQueryKey = [`${comment.id}-comment-replies`];+ const { data, fetchNextPage, isFetching } = useInfiniteQuery({+ queryKey: replyQueryKey,+ queryFn: ({ pageParam = 1 }) =>+ getPaginatedComments({ rootId, rootType: type, page: pageParam, parentId: comment.id }),+ getNextPageParam: (_, pages) => pages?.length + 1,+ staleTime: 5000,+ });++ async function createChallengeCommentReply() {try {- await copyCommentUrlToClipboard();- toast({- title: 'Success!',- variant: 'success',- description: <p>Copied comment URL to clipboard!</p>,- });- } catch (error) {- console.error(error);+ const res = await replyComment(+ {+ text: replyText,+ rootId,+ rootType: type,+ },+ comment.id,+ );+ if (res === 'text_is_empty') {+ toast({+ title: 'Empty Comment',+ description: <p>You cannot post an empty comment.</p>,+ });+ } else if (res === 'unauthorized') {+ toast({+ title: 'Unauthorized',+ description: <p>You need to be signed in to post a comment.</p>,+ });+ }+ setReplyText('');+ queryClient.invalidateQueries(replyQueryKey);+ queryClient.invalidateQueries(queryKey);+ setShowReplies(true);+ } catch (e) {toast({- title: 'Failure!',+ title: 'Unauthorized',variant: 'destructive',- description: <p>Something went wrong!</p>,+ description: <p>You need to be signed in to post a comment.</p>,});}}- const handleEnterKey = async (e: React.KeyboardEvent<HTMLTextAreaElement>) => {- if (e.shiftKey && e.key === 'Enter') {- e.preventDefault();- await updateChallengeComment();- }- };++ const toggleReplies = () => setShowReplies(!showReplies);+ const toggleIsReplying = () => setIsReplying(!isReplying);++ return (+ <div className="flex flex-col p-2">+ <SingleComment comment={comment} readonly={readonly} onClickReply={toggleIsReplying} />+ {isReplying && (+ <div className="pb-2 pl-6">+ <CommentInput+ value={replyText}+ onCancel={() => {+ setIsReplying(false);+ }}+ onChange={setReplyText}+ onSubmit={async () => {+ await createChallengeCommentReply();+ setIsReplying(false);+ }}+ mode="edit"+ />+ </div>+ )}+ {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">+ {data?.pages.flatMap((page) =>+ page.comments.map((reply) => (+ // this is a reply+ <SingleComment key={comment.id} comment={reply} isReply replyQueryKey={replyQueryKey} />+ )),+ )}+ </div>+ )}+ {!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"+ onClick={() => fetchNextPage()}+ >+ Load more+ </button>+ )}+ </div>+ );+};++const SingleComment = ({+ comment,+ readonly = false,+ onClickReply,+ isReply,+ queryKey,+ replyQueryKey+}: SingleCommentProps) => {+ const queryClient = useQueryClient();+ const [text, setText] = useState(comment.text);+ const [isEditing, setIsEditing] = useState(false);async function updateChallengeComment() {try {@@ -87,6 +185,7 @@ export const Comment = ({ comment, queryKey, readonly = false }: CommentProps) =});}queryClient.invalidateQueries(queryKey);+ queryClient.invalidateQueries(replyQueryKey);} catch (e) {toast({title: 'Unauthorized',@@ -96,6 +195,24 @@ export const Comment = ({ comment, queryKey, readonly = false }: CommentProps) =}}+ async function copyPathNotifyUser() {+ try {+ await copyCommentUrlToClipboard();+ toast({+ title: 'Success!',+ variant: 'success',+ description: <p>Copied comment URL to clipboard!</p>,+ });+ } catch (error) {+ console.error(error);+ toast({+ title: 'Failure!',+ variant: 'destructive',+ description: <p>Something went wrong!</p>,+ });+ }+ }+async function copyCommentUrlToClipboard() {await navigator.clipboard.writeText(`${window.location.href}/comment/${comment.id}`);}@@ -105,7 +222,7 @@ export const Comment = ({ comment, queryKey, readonly = false }: CommentProps) =const isAuthor = loggedinUser.data?.user?.id === comment.user.id;return (- <div className="flex flex-col gap-1 p-3 pt-2">+ <><div className="flex items-start justify-between gap-4 pr-[0.4rem]"><div className="flex items-center gap-1"><UserBadge username={comment.user.name ?? ''} />@@ -134,10 +251,15 @@ export const Comment = ({ comment, queryKey, readonly = false }: CommentProps) =<div className="hidden text-[0.8rem] sm:block">Share</div></div>{/* TODO: make dis work */}- <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">- <Reply className="h-4 w-4" />- <div className="hidden text-[0.8rem] sm:block">Reply</div>- </button>+ {!isReply && (+ <button+ className="flex cursor-pointer items-center gap-1 text-neutral-500 duration-200 disabled:text-neutral-700 dark:text-neutral-400 dark:hover:text-neutral-300"+ onClick={onClickReply}+ >+ <Reply className="h-4 w-4" />+ <div className="hidden text-[0.8rem] sm:block">Reply</div>+ </button>+ )}{isAuthor && (<buttononClick={() => setIsEditing(!isEditing)}@@ -147,9 +269,8 @@ export const Comment = ({ comment, queryKey, readonly = false }: CommentProps) =<div className="hidden text-[0.8rem] sm:block">Edit</div></button>)}- {/* TODO: make dis work */}{isAuthor ? (- <CommentDeleteDialog comment={comment} queryKey={queryKey} asChild>+ <CommentDeleteDialog comment={comment} asChild><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"><Trash2 className="h-3 w-3" /><div className="hidden text-[0.8rem] sm:block">Delete</div>@@ -176,7 +297,6 @@ export const Comment = ({ comment, queryKey, readonly = false }: CommentProps) =setIsEditing(false);}}onChange={setText}- onKeyDown={handleEnterKey}onSubmit={async () => {await updateChallengeComment();setIsEditing(false);@@ -186,7 +306,7 @@ export const Comment = ({ comment, queryKey, readonly = false }: CommentProps) =</div>)}</div>- </div>+ </>);};diff --git a/src/components/challenge/comments/delete/index.tsx b/src/components/challenge/comments/delete/index.tsxindex 0405f525..78ef8f4f 100644--- a/src/components/challenge/comments/delete/index.tsx+++ b/src/components/challenge/comments/delete/index.tsx@@ -1,5 +1,4 @@import { type DialogTriggerProps } from '@radix-ui/react-dialog';-import { useQueryClient } from '@tanstack/react-query';import { useState } from 'react';import { TypographyP } from '~/components//ui/paragraph';import { Button } from '~/components/ui/button';@@ -9,6 +8,7 @@ import { TypographyLarge } from '~/components/ui/typography/large';import { toast } from '~/components/ui/use-toast';import { getRelativeTime } from '~/utils/relativeTime';import { deleteComment, type CommentsByChallengeId } from '../comment.action';+import { useQueryClient } from '@tanstack/react-query';interface CommentDeleteDialogProps extends DialogTriggerProps {comment: CommentsByChallengeId[number];@@ -21,8 +21,8 @@ export const CommentDeleteDialog = ({queryKey,...props}: CommentDeleteDialogProps) => {- const [isOpen, setIsOpen] = useState(false);const queryClient = useQueryClient();+ const [isOpen, setIsOpen] = useState(false);async function handleDeleteComment() {try {diff --git a/src/components/challenge/comments/getCommentRouteData.ts b/src/components/challenge/comments/getCommentRouteData.tsindex 690980e4..ffe7a705 100644--- a/src/components/challenge/comments/getCommentRouteData.ts+++ b/src/components/challenge/comments/getCommentRouteData.ts@@ -2,30 +2,36 @@import type { CommentRoot } from '@prisma/client';import { prisma } from '~/server/db';+const PAGESIZE = 10;+export type PaginatedComments = NonNullable<Awaited<ReturnType<typeof getPaginatedComments>>>;export async function getPaginatedComments({page,rootId,rootType,+ parentId = null,}: {+ page: number;rootId: number;rootType: CommentRoot;- page: number;+ parentId?: number | null;}) {const totalComments = await prisma.comment.count({where: {rootType,+ parentId: parentId,visible: true,...(rootType === 'CHALLENGE' ? { rootChallengeId: rootId } : { rootSolutionId: rootId }),},});const comments = await prisma.comment.findMany({- skip: (page - 1) * 10,- take: 10,+ skip: (page - 1) * PAGESIZE,+ take: PAGESIZE,where: {rootType,+ parentId: parentId,...(rootType === 'CHALLENGE' ? { rootChallengeId: rootId } : { rootSolutionId: rootId }),visible: true,},@@ -34,14 +40,23 @@ export async function getPaginatedComments({},include: {user: true,+ _count: {+ select: {+ replies: true,+ },+ },+ rootChallenge: true,+ rootSolution: true,},});- const totalPages = Math.ceil(totalComments / 10);+ const totalPages = Math.ceil(totalComments / PAGESIZE);++ const totalReplies = comments.reduce((a, c) => a + c._count.replies, 0);return {+ totalComments: totalReplies + totalComments,totalPages,- totalComments,hasMore: page < totalPages,comments,};diff --git a/src/components/challenge/comments/index.tsx b/src/components/challenge/comments/index.tsxindex 0b5ce236..89ac8b39 100644--- a/src/components/challenge/comments/index.tsx+++ b/src/components/challenge/comments/index.tsx@@ -4,7 +4,6 @@ import type { CommentRoot } from '@prisma/client';import { useQuery, useQueryClient } from '@tanstack/react-query';import clsx from 'clsx';import { ChevronDown, ChevronLeft, ChevronRight, MessageCircle } from 'lucide-react';-import { useRouter } from 'next/navigation';import { useRef, useState } from 'react';import { Comment } from '~/components/challenge/comments/comment';import { Button } from '~/components/ui/button';@@ -25,7 +24,6 @@ export const Comments = ({ rootId, type }: Props) => {const [text, setText] = useState('');const commentContainerRef = useRef<HTMLDivElement>(null);const queryClient = useQueryClient();- const router = useRouter();const [page, setPage] = useState(1);@@ -38,13 +36,6 @@ export const Comments = ({ rootId, type }: Props) => {staleTime: 5000,});- const handleEnterKey = async (e: React.KeyboardEvent<HTMLTextAreaElement>) => {- if (e.shiftKey && e.key === 'Enter') {- e.preventDefault();- await createChallengeComment();- }- };-async function createChallengeComment() {try {const res = await addComment({@@ -71,8 +62,6 @@ export const Comments = ({ rootId, type }: Props) => {variant: 'destructive',description: <p>You need to be signed in to post a comment.</p>,});- } finally {- router.refresh();}}@@ -87,7 +76,7 @@ export const Comments = ({ rootId, type }: Props) => {return (<divclassName={clsx(- 'sticky bottom-0 overflow-hidden border-t border-zinc-300 bg-background/90 shadow-[0_0_3rem_-0.25rem_#0004] backdrop-blur-sm duration-300 dark:border-zinc-700 dark:border-b-muted dark:bg-muted/90 dark:shadow-[0_0_3rem_-0.25rem_#0008]',+ 'absolute bottom-0 w-full overflow-hidden border-t border-zinc-300 bg-background/90 shadow-[0_0_3rem_-0.25rem_#0004] backdrop-blur-sm duration-300 dark:border-zinc-700 dark:border-b-muted dark:bg-muted/90 dark:shadow-[0_0_3rem_-0.25rem_#0008]',{'lg:border-t-none': showComments,},@@ -124,7 +113,6 @@ export const Comments = ({ rootId, type }: Props) => {<CommentInputonChange={setText}value={text}- onKeyDown={handleEnterKey}onSubmit={createChallengeComment}mode="create"/>@@ -136,7 +124,13 @@ export const Comments = ({ rootId, type }: Props) => {<NoComments />) : (data?.comments?.map((comment) => (- <Comment key={comment.id} comment={comment} queryKey={queryKey} />+ <Comment+ key={comment.id}+ comment={comment}+ rootId={rootId}+ type={type}+ queryKey={queryKey}+ />))))}</div>diff --git a/src/components/challenge/description/index.tsx b/src/components/challenge/description/index.tsxindex 0c5209b0..b90234fc 100644--- a/src/components/challenge/description/index.tsx+++ b/src/components/challenge/description/index.tsx@@ -9,7 +9,6 @@ import { useRef, useState } from 'react';import { Bookmark as BookmarkIcon, Share, ThumbsUp } from 'lucide-react';import { Button } from '~/components/ui/button';-import { UserBadge } from '~/components/ui/user-badge';import {Dialog,DialogContent,@@ -17,18 +16,19 @@ import {DialogTitle,DialogTrigger,} from '~/components/ui/dialog';-import { Tooltip, TooltipContent, TooltipTrigger } from '~/components/ui/tooltip';-import { TypographyH3 } from '~/components/ui/typography/h3';import { DifficultyBadge } from '~/components/ui/difficulty-badge';-import { ActionMenu } from '~/components/ui/action-menu';import { Markdown } from '~/components/ui/markdown';+import { Tooltip, TooltipContent, TooltipTrigger } from '~/components/ui/tooltip';+import { TypographyH3 } from '~/components/ui/typography/h3';+import { UserBadge } from '~/components/ui/user-badge';import { ShareForm } from '../share-form';import { type ChallengeRouteData } from '~/app/challenge/[id]/getChallengeRouteData';-import { addOrRemoveBookmark } from '../bookmark.action';-import { incrementOrDecrementUpvote } from '../increment.action';import ReportDialog from '~/components/report';+import { ActionMenu } from '~/components/ui/action-menu';import { getRelativeTime } from '~/utils/relativeTime';+import { addOrRemoveBookmark } from '../bookmark.action';+import { incrementOrDecrementUpvote } from '../increment.action';interface Props {challenge: ChallengeRouteData;diff --git a/src/components/report/report.action.ts b/src/components/report/report.action.tsindex 2daa176d..0008566d 100644--- a/src/components/report/report.action.ts+++ b/src/components/report/report.action.ts@@ -1,9 +1,8 @@'use server';-import { prisma } from '~/server/db';-import type { FormValues } from '../challenge/description';-import { type Report, type Prisma } from '@prisma/client';+import { type Prisma, type Report } from '@prisma/client';import { getServerAuthSession } from '~/server/auth';+import { prisma } from '~/server/db';export type ReportBase = {issues: Prisma.ReportIssueCreateWithoutReportInput[];@@ -188,6 +187,13 @@ export async function getReportedUserInformation(userId: string) {take: 10,include: {user: true,+ _count: {+ select: {+ replies: true,+ },+ },+ rootChallenge: true,+ rootSolution: true,},orderBy: {createdAt: 'desc',diff --git a/src/components/report/types/comment.report.tsx b/src/components/report/types/comment.report.tsxindex aefa9862..f85c377e 100644--- a/src/components/report/types/comment.report.tsx+++ b/src/components/report/types/comment.report.tsx@@ -4,6 +4,7 @@ import { Comment } from '~/components/challenge/comments/comment';export default function CommentReport({ report }: { report: NonNullable<ReportWithInfo> }) {if (report.type !== 'COMMENT' || report.commentId === null || !report.comment) return null;+ const rootId = report.comment.rootChallengeId ?? report.comment.rootSolutionId ?? -1;return (<div>@@ -24,7 +25,7 @@ export default function CommentReport({ report }: { report: NonNullable<ReportWi</Link></header><section className="mt-4 rounded-lg bg-zinc-800">- <Comment comment={report.comment} readonly />+ <Comment rootId={rootId} type={report.comment.rootType} comment={report.comment} readonly /></section></div>);diff --git a/src/components/report/types/user.report.tsx b/src/components/report/types/user.report.tsxindex a312ed64..45df644a 100644--- a/src/components/report/types/user.report.tsx+++ b/src/components/report/types/user.report.tsx@@ -14,6 +14,8 @@ interface UserReportProps {export default async function UserReportUi({ report }: UserReportProps) {if (!report.userId) return null;const userInfo = await getReportedUserInformation(report.userId);+ const commentRootId = report?.comment?.rootChallengeId ?? report?.comment?.rootSolutionId ?? -1;+return (<div><Text intent="h3">@@ -22,9 +24,12 @@ export default async function UserReportUi({ report }: UserReportProps) {<div className="mt-4 flex flex-col gap-4">{userInfo.comment &&- userInfo.comment.map((m) => (- <div key={`comment-${m.id}`} className="rounded border border-zinc-700 bg-zinc-800 p-2">- <Comment readonly comment={m} />+ userInfo.comment.map((comment) => (+ <div+ key={`comment-${comment.id}`}+ className="rounded border border-zinc-700 bg-zinc-800 p-2"+ >+ <Comment readonly comment={comment} rootId={commentRootId} type={comment.rootType} /></div>))}