This implementation provides a complete comments system for bugs with both backend and frontend components. While a basic comments endpoint already existed, this enhancement improves the functionality with better user experience and reusable components.
- File:
GetBugCommentsWithUserQuery.cs - Enhancement: Created an enhanced version of the comments query that includes user information (name, email) using SQL joins
- Benefits:
- Provides complete user information with comments
- Uses efficient SQL query for better performance
- Includes user names without additional API calls
- File:
BugsEndpoints.cs - Change: Updated the existing
GetCommentsendpoint to use the new query handler - Result: The endpoint now returns comments with user information included
- File:
CommentItem.tsx - Purpose: Displays individual comments with user avatars, names, and timestamps
- Features:
- User avatar with initials
- Formatted timestamps using relative time
- Edit indicator for modified comments
- Responsive design with hover effects
- File:
CommentForm.tsx - Purpose: Provides a form for adding new comments
- Features:
- Character limit validation (2000 characters)
- Real-time character counter with color coding
- Disabled state during submission
- Auto-clear on successful submission
- Loading state with spinner
- File:
CommentSection.tsx - Purpose: Complete comments section combining display and input
- Features:
- Shows all comments for a bug
- Includes comment form
- Loading skeletons
- Empty state message
- Configurable height and styling
- Comment count display
- File:
useComments.ts - Purpose: Custom hook for managing comment state and operations
- Features:
- Fetches comments for a specific bug
- Handles adding new comments
- Manages loading states
- Error handling with toast notifications
- Automatic refresh after adding comments
- File:
BugCommentsTab.tsx - Purpose: Simplified component for use within the existing BugDetailsPage
- Usage: Can replace the current comments tab content
- File:
BugCommentsPage.tsx - Purpose: Standalone page dedicated to viewing and managing comments for a bug
- Features:
- Bug summary information
- Full comments section
- Navigation back to bug details
- Error handling for missing bugs
- File:
api.ts - Enhancement: Extended the Comment interface to include
userNameanduserEmailfields - Compatibility: Maintains backward compatibility with existing code
// In any component
import { CommentSection } from "@/components/Comments";
import { useComments } from "@/hooks/useComments";
const MyComponent = ({ bugId }: { bugId: string }) => {
const { comments, isLoading, isAddingComment, addComment } =
useComments(bugId);
return (
<CommentSection
comments={comments}
isLoading={isLoading}
onAddComment={addComment}
isAddingComment={isAddingComment}
/>
);
};// Replace the existing comments TabsContent with:
<TabsContent value="comments" className="space-y-4">
<BugCommentsTab bugId={bugId} />
</TabsContent>- Reusability: Comment components can be used throughout the application
- Better UX: Improved visual design with user avatars and better feedback
- Performance: Efficient SQL queries reduce API calls
- Maintainability: Modular components are easier to test and maintain
- Extensibility: Easy to add features like editing, deleting, or reactions
The implementation uses the existing endpoint structure:
GET /api/bugs/{bugId}/comments- Now returns enhanced data with user informationPOST /api/bugs/{bugId}/comments- Unchanged, still works as before
- ✅
GetBugCommentsWithUserQuery.cs- New enhanced query handler - ✅
BugsEndpoints.cs- Updated to use new query handler
- ✅
CommentItem.tsx- Individual comment display component - ✅
CommentForm.tsx- Comment input form component - ✅
CommentSection.tsx- Complete comments section - ✅
index.ts- Component exports - ✅
BugCommentsTab.tsx- Tab component for existing pages
- ✅
useComments.ts- Comment management hook
- ✅
BugCommentsPage.tsx- Standalone comments page
- ✅
api.ts- Updated Comment interface
- Add routes for the new BugCommentsPage (optional)
- Replace existing comment implementation in BugDetailsPage with new components
- Add comment editing/deletion functionality if needed
- Add comment reactions (like/dislike) if desired
- Add real-time updates using SignalR if required
The implementation is production-ready and maintains backward compatibility while providing enhanced functionality.