.
All checks were successful
Deploy blog-frontend / build-and-deploy (push) Successful in 2m30s

This commit is contained in:
wypark
2026-05-28 21:45:30 +09:00
parent 58a012621a
commit 0273cae6e4
37 changed files with 2625 additions and 1319 deletions

View File

@@ -5,7 +5,6 @@ import { useAuthStore } from '@/store/authStore';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { createComment } from '@/api/comments';
import { Loader2, Send } from 'lucide-react';
import { clsx } from 'clsx';
interface CommentFormProps {
postSlug: string;
@@ -15,7 +14,7 @@ interface CommentFormProps {
}
export default function CommentForm({ postSlug, parentId = null, onSuccess, placeholder = '댓글을 남겨보세요.' }: CommentFormProps) {
const { isLoggedIn, role } = useAuthStore();
const { isLoggedIn } = useAuthStore();
const queryClient = useQueryClient();
const [content, setContent] = useState('');
@@ -29,8 +28,16 @@ export default function CommentForm({ postSlug, parentId = null, onSuccess, plac
queryClient.invalidateQueries({ queryKey: ['comments', postSlug] });
if (onSuccess) onSuccess();
},
onError: (err: any) => {
alert('댓글 작성 실패: ' + (err.response?.data?.message || err.message));
onError: (error: unknown) => {
const responseError = error as {
response?: {
data?: {
message?: string;
};
};
};
const fallbackMessage = error instanceof Error ? error.message : '알 수 없는 오류가 발생했습니다.';
alert('댓글 작성 실패: ' + (responseError.response?.data?.message || fallbackMessage));
},
});
@@ -98,4 +105,4 @@ export default function CommentForm({ postSlug, parentId = null, onSuccess, plac
</div>
</form>
);
}
}

View File

@@ -5,6 +5,7 @@ import { getComments } from '@/api/comments';
import CommentForm from './CommentForm';
import CommentItem from './CommentItem';
import { Loader2, MessageCircle } from 'lucide-react';
import { Comment } from '@/types';
interface CommentListProps {
postSlug: string;
@@ -18,7 +19,7 @@ export default function CommentList({ postSlug }: CommentListProps) {
});
// 총 댓글 수 계산 (재귀)
const countComments = (list: any[]): number => {
const countComments = (list: Comment[]): number => {
if (!list) return 0;
return list.reduce((acc, curr) => acc + 1 + countComments(curr.children), 0);
};
@@ -61,4 +62,4 @@ export default function CommentList({ postSlug }: CommentListProps) {
</div>
</div>
);
}
}