From 6a144fb2fb81efa1cf58b075c4b77fcf90434430 Mon Sep 17 00:00:00 2001
From: Neeraj-code-beep
Date: Tue, 26 May 2026 23:11:54 +0530
Subject: [PATCH] fix api routes
---
client/src/components/CommentSection.jsx | 188 ++++----
.../src/components/NotificationDropdown.jsx | 174 ++++----
client/src/components/QuestionCard.jsx | 168 ++++---
client/src/components/TagFilter.jsx | 82 ++--
client/src/contexts/AuthContext.jsx | 192 ++++----
client/src/contexts/SocketContext.jsx | 122 +++---
client/src/pages/AdminDashboard.jsx | 398 +++++++++++------
client/src/pages/AskQuestionPage.jsx | 150 ++++---
client/src/pages/QuestionDetailPage.jsx | 333 +++++++-------
client/src/pages/QuestionsFeed.jsx | 182 ++++----
client/src/pages/SettingsPage.jsx | 411 +++++++++++-------
client/src/pages/TagManagementPage.jsx | 284 +++++++-----
client/src/pages/UserProfilePage.jsx | 223 ++++++----
client/src/utils/api.js | 85 ++--
14 files changed, 1744 insertions(+), 1248 deletions(-)
diff --git a/client/src/components/CommentSection.jsx b/client/src/components/CommentSection.jsx
index 61f713b..911157b 100644
--- a/client/src/components/CommentSection.jsx
+++ b/client/src/components/CommentSection.jsx
@@ -1,101 +1,107 @@
-import { useState } from 'react'
-import { useMutation, useQueryClient } from 'react-query'
-import { toast } from 'react-hot-toast'
-import {
- FiMessageSquare,
- FiUser,
- FiClock,
- FiEdit,
+import { useState } from 'react';
+import { useMutation, useQueryClient } from 'react-query';
+import { toast } from 'react-hot-toast';
+import {
+ FiMessageSquare,
+ FiUser,
+ FiClock,
+ FiEdit,
FiTrash2,
- FiX
-} from 'react-icons/fi'
-import { useAuth } from '../contexts/AuthContext'
-import api from '../utils/api'
+ FiX,
+} from 'react-icons/fi';
+import { useAuth } from '../contexts/AuthContext';
+import api from '../utils/api';
const CommentSection = ({ contentType, contentId, comments = [] }) => {
- const [showForm, setShowForm] = useState(false)
- const [commentText, setCommentText] = useState('')
- const [editingComment, setEditingComment] = useState(null)
- const { user } = useAuth()
- const queryClient = useQueryClient()
+ const [showForm, setShowForm] = useState(false);
+ const [commentText, setCommentText] = useState('');
+ const [editingComment, setEditingComment] = useState(null);
+ const { user } = useAuth();
+ const queryClient = useQueryClient();
const addCommentMutation = useMutation(
- (text) => api.post('/comments', {
- contentType,
- contentId,
- content: text
- }),
+ text =>
+ api.post('api/comments', {
+ contentType,
+ contentId,
+ content: text,
+ }),
{
onSuccess: () => {
- queryClient.invalidateQueries(['question', contentId])
- setCommentText('')
- setShowForm(false)
- toast.success('Comment added successfully!')
+ queryClient.invalidateQueries(['question', contentId]);
+ setCommentText('');
+ setShowForm(false);
+ toast.success('Comment added successfully!');
+ },
+ onError: error => {
+ toast.error(error.response?.data?.message || 'Failed to add comment');
},
- onError: (error) => {
- toast.error(error.response?.data?.message || 'Failed to add comment')
- }
}
- )
+ );
const updateCommentMutation = useMutation(
- ({ commentId, content }) => api.put(`/comments/${commentId}`, { content }),
+ ({ commentId, content }) =>
+ api.put(`api/comments/${commentId}`, { content }),
{
onSuccess: () => {
- queryClient.invalidateQueries(['question', contentId])
- setEditingComment(null)
- toast.success('Comment updated successfully!')
+ queryClient.invalidateQueries(['question', contentId]);
+ setEditingComment(null);
+ toast.success('Comment updated successfully!');
+ },
+ onError: error => {
+ toast.error(
+ error.response?.data?.message || 'Failed to update comment'
+ );
},
- onError: (error) => {
- toast.error(error.response?.data?.message || 'Failed to update comment')
- }
}
- )
+ );
const deleteCommentMutation = useMutation(
- (commentId) => api.delete(`/comments/${commentId}`),
+ commentId => api.delete(`api/comments/${commentId}`),
{
onSuccess: () => {
- queryClient.invalidateQueries(['question', contentId])
- toast.success('Comment deleted successfully!')
+ queryClient.invalidateQueries(['question', contentId]);
+ toast.success('Comment deleted successfully!');
+ },
+ onError: error => {
+ toast.error(
+ error.response?.data?.message || 'Failed to delete comment'
+ );
},
- onError: (error) => {
- toast.error(error.response?.data?.message || 'Failed to delete comment')
- }
}
- )
+ );
const handleSubmit = () => {
if (!commentText.trim()) {
- toast.error('Please enter a comment')
- return
+ toast.error('Please enter a comment');
+ return;
}
- addCommentMutation.mutate(commentText)
- }
+ addCommentMutation.mutate(commentText);
+ };
- const handleUpdate = (commentId) => {
+ const handleUpdate = commentId => {
if (!commentText.trim()) {
- toast.error('Please enter a comment')
- return
+ toast.error('Please enter a comment');
+ return;
}
- updateCommentMutation.mutate({ commentId, content: commentText })
- }
+ updateCommentMutation.mutate({ commentId, content: commentText });
+ };
- const handleDelete = (commentId) => {
+ const handleDelete = commentId => {
if (window.confirm('Are you sure you want to delete this comment?')) {
- deleteCommentMutation.mutate(commentId)
+ deleteCommentMutation.mutate(commentId);
}
- }
+ };
- const startEditing = (comment) => {
- setEditingComment(comment._id)
- setCommentText(comment.content)
- }
+ const startEditing = comment => {
+ setEditingComment(comment._id);
+ setCommentText(comment.content);
+ };
const cancelEditing = () => {
- setEditingComment(null)
- setCommentText('')
- }
+ setEditingComment(null);
+ setCommentText('');
+ };
return (
@@ -125,7 +131,7 @@ const CommentSection = ({ contentType, contentId, comments = [] }) => {
- )
+ );
}
if (isLoading) {
@@ -116,12 +130,15 @@ const AdminDashboard = () => {
{[...Array(4)].map((_, i) => (
-
+
))}
- )
+ );
}
if (error) {
@@ -131,46 +148,56 @@ const AdminDashboard = () => {
Error loading admin data: {error.message}
- )
+ );
}
- const { stats, pendingContent, reportedContent, recentUsers, recentActivity } = adminData
+ const {
+ stats,
+ pendingContent,
+ reportedContent,
+ recentUsers,
+ recentActivity,
+ } = adminData;
const tabs = [
{ id: 'overview', label: 'Overview', icon: FiBarChart2 },
{ id: 'moderation', label: 'Content Moderation', icon: FiShield },
{ id: 'users', label: 'User Management', icon: FiUsers },
{ id: 'reports', label: 'Reports', icon: FiFlag },
- { id: 'activity', label: 'Recent Activity', icon: FiActivity }
- ]
+ { id: 'activity', label: 'Recent Activity', icon: FiActivity },
+ ];
const handleApprove = (contentType, contentId) => {
- approveContentMutation.mutate({ contentType, contentId })
- }
+ approveContentMutation.mutate({ contentType, contentId });
+ };
const handleReject = (contentType, contentId, reason) => {
- rejectContentMutation.mutate({ contentType, contentId, reason })
- }
+ rejectContentMutation.mutate({ contentType, contentId, reason });
+ };
const handleBanUser = (userId, reason, duration) => {
- banUserMutation.mutate({ userId, reason, duration })
- }
+ banUserMutation.mutate({ userId, reason, duration });
+ };
const handleDeleteContent = (contentType, contentId) => {
- if (window.confirm('Are you sure you want to delete this content? This action cannot be undone.')) {
- deleteContentMutation.mutate({ contentType, contentId })
+ if (
+ window.confirm(
+ 'Are you sure you want to delete this content? This action cannot be undone.'
+ )
+ ) {
+ deleteContentMutation.mutate({ contentType, contentId });
}
- }
+ };
- const formatDate = (date) => {
+ const formatDate = date => {
return new Date(date).toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
- minute: '2-digit'
- })
- }
+ minute: '2-digit',
+ });
+ };
return (
@@ -196,8 +223,12 @@ const AdminDashboard = () => {
-
Total Users
-
{stats.totalUsers}
+
+ Total Users
+
+
+ {stats.totalUsers}
+
@@ -208,8 +239,12 @@ const AdminDashboard = () => {
-
Total Questions
-
{stats.totalQuestions}
+
+ Total Questions
+
+
+ {stats.totalQuestions}
+
@@ -220,8 +255,12 @@ const AdminDashboard = () => {
-
Pending Review
-
{pendingContent.length}
+
+ Pending Review
+
+
+ {pendingContent.length}
+
@@ -232,8 +271,12 @@ const AdminDashboard = () => {
-
Reports
-
{reportedContent.length}
+
+ Reports
+
+
+ {reportedContent.length}
+
@@ -248,8 +291,8 @@ const AdminDashboard = () => {
>
@@ -283,20 +326,31 @@ const AdminDashboard = () => {
Recent Users
- {recentUsers.map((user) => (
-
+ {recentUsers.map(user => (
+
-
{user.username}
-
{user.email}
+
+ {user.username}
+
+
+ {user.email}
+
-
{user.reputation}
-
reputation
+
+ {user.reputation}
+
+
+ reputation
+
))}
@@ -310,13 +364,20 @@ const AdminDashboard = () => {
{recentActivity.map((activity, index) => (
-
+
-
{activity.description}
-
{formatDate(activity.date)}
+
+ {activity.description}
+
+
+ {formatDate(activity.date)}
+
))}
@@ -331,7 +392,7 @@ const AdminDashboard = () => {
Pending Content Review
{pendingContent.length > 0 ? (
- pendingContent.map((content) => (
+ pendingContent.map(content => (
@@ -346,32 +407,36 @@ const AdminDashboard = () => {
{formatDate(content.createdAt)}
-
+
{content.type === 'question' && (
)}
-
+
{content.type === 'answer' && (
Answer to: {content.question.title}
-
)}
-
+