@@ -4,6 +4,7 @@ import { commentService, CommentResponse } from '../services/commentService'
44import { MessageCircle , Send , Edit2 , Trash2 , Loader2 , Reply , Flag , AlertTriangle } from 'lucide-react'
55import UserAvatar from './UserAvatar'
66import toast from 'react-hot-toast'
7+ import { apiRequest } from '../utils/requestQueue'
78
89interface CommentSectionProps {
910 postId : string
@@ -34,9 +35,10 @@ const CommentSection: React.FC<CommentSectionProps> = ({ postId, className = '',
3435 const loadComments = async ( ) => {
3536 try {
3637 setIsLoading ( true )
38+ // Use request queue with normal priority for comments
3739 const [ commentsData , count ] = await Promise . all ( [
38- commentService . getCommentsWithReplies ( postId , 10 , 0 ) , // Use threaded comments
39- commentService . getCommentCount ( postId )
40+ apiRequest . normal ( ( ) => commentService . getCommentsWithReplies ( postId , 10 , 0 ) , ` comments- ${ postId } ` ) ,
41+ apiRequest . normal ( ( ) => commentService . getCommentCount ( postId ) , `comment-count- ${ postId } ` )
4042 ] )
4143 setComments ( commentsData . comments )
4244 setCommentCount ( count )
@@ -62,9 +64,10 @@ const CommentSection: React.FC<CommentSectionProps> = ({ postId, className = '',
6264
6365 setIsSubmitting ( true )
6466 try {
65- const comment = await commentService . createComment ( postId , {
67+ // Use high priority for user interactions
68+ const comment = await apiRequest . high ( ( ) => commentService . createComment ( postId , {
6669 content : newComment . trim ( )
67- } )
70+ } ) )
6871 setComments ( prev => [ comment , ...prev ] )
6972 setCommentCount ( prev => prev + 1 )
7073 setNewComment ( '' )
@@ -80,9 +83,10 @@ const CommentSection: React.FC<CommentSectionProps> = ({ postId, className = '',
8083 if ( ! editContent . trim ( ) ) return
8184
8285 try {
83- const updatedComment = await commentService . updateComment ( commentId , {
86+ // Use high priority for user interactions
87+ const updatedComment = await apiRequest . high ( ( ) => commentService . updateComment ( commentId , {
8488 content : editContent . trim ( )
85- } )
89+ } ) )
8690 setComments ( prev => prev . map ( c => c . id === commentId ? updatedComment : c ) )
8791 setEditingComment ( null )
8892 setEditContent ( '' )
@@ -96,7 +100,8 @@ const CommentSection: React.FC<CommentSectionProps> = ({ postId, className = '',
96100 if ( ! confirm ( 'Are you sure you want to delete this comment?' ) ) return
97101
98102 try {
99- await commentService . deleteComment ( commentId )
103+ // Use high priority for user interactions
104+ await apiRequest . high ( ( ) => commentService . deleteComment ( commentId ) )
100105 setComments ( prev => prev . filter ( c => c . id !== commentId ) )
101106 setCommentCount ( prev => prev - 1 )
102107 toast . success ( 'Comment deleted successfully' )
@@ -113,10 +118,11 @@ const CommentSection: React.FC<CommentSectionProps> = ({ postId, className = '',
113118 if ( ! replyContent . trim ( ) ) return
114119
115120 try {
116- const reply = await commentService . createComment ( postId , {
121+ // Use high priority for user interactions
122+ const reply = await apiRequest . high ( ( ) => commentService . createComment ( postId , {
117123 content : replyContent . trim ( ) ,
118124 parentCommentId
119- } )
125+ } ) )
120126
121127 // Add reply to the parent comment's replies array
122128 setComments ( prev => prev . map ( comment => {
@@ -145,10 +151,11 @@ const CommentSection: React.FC<CommentSectionProps> = ({ postId, className = '',
145151 }
146152
147153 try {
148- await commentService . reportComment ( commentId , {
154+ // Use normal priority for reporting
155+ await apiRequest . normal ( ( ) => commentService . reportComment ( commentId , {
149156 reason : reportReason ,
150157 details : reportDetails || undefined
151- } )
158+ } ) )
152159
153160 setReportingComment ( null )
154161 setReportReason ( 'spam' )
0 commit comments