Skip to content

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

cleanup: disable comments for not logged in, hide pagination

bautistaaa767379e47f44
diff --git a/src/components/challenge/code-panel/index.tsx b/src/components/challenge/code-panel/index.tsx
index 1dd37d9d..adda1409 100644
--- a/src/components/challenge/code-panel/index.tsx
+++ b/src/components/challenge/code-panel/index.tsx
@@ -101,7 +101,7 @@ export const CodePanel = (props: Props) => {
variant: 'success',
title: 'Good job!',
description: 'You completed this challenge.',
- action: <ToastAction altText="Try again">Dismiss</ToastAction>,
+ action: <ToastAction altText="Dismiss">Dismiss</ToastAction>,
});
}
};
diff --git a/src/components/challenge/comments/comment-input.tsx b/src/components/challenge/comments/comment-input.tsx
index c8c14cfd..513e3f79 100644
--- a/src/components/challenge/comments/comment-input.tsx
+++ b/src/components/challenge/comments/comment-input.tsx
@@ -1,8 +1,11 @@
import { Loader2 } from 'lucide-react';
+import { useSession } from 'next-auth/react';
import { useEffect, useRef, useState, type RefObject } from 'react';
import { Button } from '~/components/ui/button';
import { Markdown } from '~/components/ui/markdown';
import { Textarea } from '~/components/ui/textarea';
+import { ToastAction } from '~/components/ui/toast';
+import { useToast } from '~/components/ui/use-toast';
interface Props {
mode: 'edit' | 'create';
@@ -14,6 +17,8 @@ interface Props {
}
export function CommentInput({ mode, onCancel, onChange, onKeyDown, value, onSubmit }: Props) {
+ const { data: session } = useSession();
+ const { toast } = useToast();
const [commentMode, setCommentMode] = useState<'editor' | 'preview'>('editor');
const [isSubmitting, setIsSubmitting] = useState(false);
const textAreaRef = useRef<HTMLTextAreaElement>(null);
@@ -60,6 +65,16 @@ export function CommentInput({ mode, onCancel, onChange, onKeyDown, value, onSub
disabled={value.length === 0 || isSubmitting}
onClick={async () => {
try {
+ 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();
diff --git a/src/components/challenge/comments/index.tsx b/src/components/challenge/comments/index.tsx
index ed27e634..5f1c033f 100644
--- a/src/components/challenge/comments/index.tsx
+++ b/src/components/challenge/comments/index.tsx
@@ -132,13 +132,15 @@ export const Comments = ({ challengeId, commentCount }: Props) => {
data?.comments?.map((comment) => <Comment key={comment.id} comment={comment} />)
))}
</div>
- <div className="mt-2 flex justify-center">
- <Pagination
- currentPage={page}
- totalPages={data?.totalPages ?? 0}
- onClick={handleChangePage}
- />
- </div>
+ {(data?.totalPages ?? 0) > 1 && (
+ <div className="mt-2 flex justify-center">
+ <Pagination
+ currentPage={page}
+ totalPages={data?.totalPages ?? 0}
+ onClick={handleChangePage}
+ />
+ </div>
+ )}
</div>
</div>
</div>