Connect, collaborate, and grow with a community of TypeScript developers
Comment Bug Fixed (#248)
metal-face5d4831256664
diff --git a/src/components/challenge/comments/comment.tsx b/src/components/challenge/comments/comment.tsxindex 487badb5..1b40b8ce 100644--- a/src/components/challenge/comments/comment.tsx+++ b/src/components/challenge/comments/comment.tsx@@ -1,6 +1,6 @@'use client';import { zodResolver } from '@hookform/resolvers/zod';-import { Delete, Trash2, Reply } from 'lucide-react';+import { Delete, Trash2, Reply, Share } from 'lucide-react';import { useState } from 'react';import { useForm } from 'react-hook-form';import { z } from 'zod';@@ -17,7 +17,6 @@ import { reportChallengeComment } from './comment.action';import { Tooltip, TooltipContent, TooltipTrigger } from '~/components/ui/tooltip';import { UserBadge } from '~/components/ui/user-badge';import { useSession } from 'next-auth/react';-// import { Markdown } from '~/components/ui/markdown';interface CommentProps {comment: ChallengeRouteData['comment'][number];@@ -59,6 +58,28 @@ const Comment = ({ comment }: 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}`);+ }+async function handleCommentReport(data: CommentReportSchemaType) {try {const res = await reportChallengeComment(data, comment.id);@@ -112,15 +133,24 @@ const Comment = ({ comment }: CommentProps) => {</Tooltip></div>- <div className="flex gap-2">+ <div className="flex items-center gap-2">+ <div+ onClick={() => {+ copyPathNotifyUser();+ }}+ className="gap-1 cursor-pointer duration-200 flex items-center hover:underline text-neutral-500 hover:text-neutral-400"+ >+ <Share className="h-3 w-3" />+ <small className="font-md text-sm leading-none">Share</small>+ </div>{/* TODO: make dis work */}- <button className="flex cursor-pointer items-center gap-1 text-sm text-neutral-400 duration-200 hover:text-neutral-500 hover:underline dark:text-neutral-600 dark:hover:text-neutral-500">+ <button className="flex cursor-pointer items-center gap-1 text-sm text-neutral-500 duration-200 hover:text-neutral-400 hover:underline dark:text-neutral-500 dark:hover:text-neutral-400"><Reply className="h-3 w-3" />Reply</button>{/* TODO: make dis work */}{isAuthor ? (- <button className="flex cursor-pointer items-center gap-1 text-sm text-neutral-400 duration-200 hover:text-neutral-500 hover:underline dark:text-neutral-600 dark:hover:text-neutral-500">+ <button className="flex cursor-pointer items-center gap-1 text-sm text-neutral-500 duration-200 hover:text-neutral-400 hover:underline dark:text-neutral-500 dark:hover:text-neutral-400"><Trash2 className="h-3 w-3" />Delete</button>@@ -134,6 +164,7 @@ const Comment = ({ comment }: CommentProps) => {Report</button>)}+</div></div><p className="w-full break-words pl-[1px] text-sm">@@ -170,6 +201,7 @@ const Comment = ({ comment }: CommentProps) => {</div><p className="max-h-[30vh] overflow-y-auto">{comment.text}</p></div>+<Form {...form}>{/* eslint-disable-next-line @typescript-eslint/no-misused-promises */}<form onSubmit={form.handleSubmit(handleCommentReport)}>@@ -295,6 +327,7 @@ const Comment = ({ comment }: CommentProps) => {</p>)}</div>+<div className="flex pt-4"><Button type="submit" className="w-full">Reportdiff --git a/src/components/challenge/comments/index.tsx b/src/components/challenge/comments/index.tsxindex cd29e5c0..ec725822 100644--- a/src/components/challenge/comments/index.tsx+++ b/src/components/challenge/comments/index.tsx@@ -10,7 +10,7 @@ import { toast } from '~/components/ui/use-toast';import NoComments from './nocomments';import { addChallengeComment } from './comment.action';import { Textarea } from '~/components/ui/textarea';-import { useInfiniteQuery } from '@tanstack/react-query';+import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query';import { useInView } from 'react-intersection-observer';import { getInfiniteComments } from './getCommentRouteData';import { CommentSkeleton } from './comment-skeleton';@@ -22,10 +22,14 @@ interface Props {commentCount: number;}++const Comments = ({ challengeId, commentCount }: Props) => {const [showComments, setShowComments] = useState(false);const [text, setText] = useState('');const [isCommenting, setIsCommenting] = useState(false);++ const queryClient = useQueryClient();const router = useRouter();const { ref, inView } = useInView();@@ -50,6 +54,7 @@ const Comments = ({ challengeId, commentCount }: Props) => {try {setIsCommenting(true);const res = await addChallengeComment(challengeId, text);+if (res === 'text_is_empty') {toast({title: 'Empty Comment',@@ -63,6 +68,7 @@ const Comments = ({ challengeId, commentCount }: Props) => {}setIsCommenting(false);setText('');+ await queryClient.invalidateQueries(['comments']);} catch (e) {toast({title: 'Unauthorized',