@@ -63,11 +63,12 @@ const Question = ({
63
63
console . log ( question ) ;
64
64
65
65
const packageMessage = ( message : SingleChatLogApiResponse ) : ChatLog => {
66
+ const userId = getUserId ( ) ;
66
67
return {
67
68
text : message . message ,
68
- title : collaborator ,
69
+ title : message . senderId === userId ? username : collaborator ,
69
70
date : new Date ( message . timestamp ) ,
70
- position : message . senderId === getUserId ( ) ? "right" : "left" ,
71
+ position : message . senderId === userId ? "right" : "left" ,
71
72
type : "text" ,
72
73
} ;
73
74
} ;
@@ -117,9 +118,22 @@ const Question = ({
117
118
} , [ collaboratorId ] ) ;
118
119
119
120
useEffect ( ( ) => {
121
+ const scrollToPercentage = ( percentage : number ) => {
122
+ if ( chatLogsListRef . current && hasMoreMessages . current ) {
123
+ const chatContainer = chatLogsListRef . current ;
124
+ const targetPosition = chatContainer . scrollHeight * percentage ;
125
+ chatContainer . scrollTop = targetPosition - chatContainer . clientHeight ;
126
+ }
127
+ } ;
128
+
120
129
const handleScroll = ( ) => {
121
130
if ( chatLogsListRef . current && chatLogsListRef . current . scrollTop === 0 ) {
122
- fetchChatLogs ( ) ;
131
+ fetchChatLogs ( ) . then ( ( ) => {
132
+ requestAnimationFrame ( ( ) => {
133
+ const percentage = Math . min ( 1 - ( chatLogsPage - 1 ) / chatLogsPage ) ;
134
+ scrollToPercentage ( percentage ) ;
135
+ } ) ;
136
+ } ) ;
123
137
}
124
138
} ;
125
139
@@ -152,7 +166,9 @@ const Question = ({
152
166
} ) ;
153
167
154
168
client . subscribe ( "/user/queue/language" , ( message ) => {
155
- const messageReceived : SingleChatLogApiResponse = JSON . parse ( message . body ) ;
169
+ const messageReceived : SingleChatLogApiResponse = JSON . parse (
170
+ message . body
171
+ ) ;
156
172
isLanguageChangeActive . current = false ;
157
173
setLanguage ( messageReceived . message ) ;
158
174
Swal . fire ( {
@@ -360,7 +376,9 @@ const Question = ({
360
376
</ Button >
361
377
</ div >
362
378
< span className = "row-span-1 text-primary-300 text-md max-h-[100%] h-full overflow-y-auto flex flex-col gap-2 bg-primary-800 p-3 rounded-md" >
363
- < span className = "text-yellow-500 font-bold text-md" > Question Description</ span >
379
+ < span className = "text-yellow-500 font-bold text-md" >
380
+ Question Description
381
+ </ span >
364
382
< span className = "text-white py-2 text-xs" > { question ?. description } </ span >
365
383
< span className = "text-yellow-500 font-bold text-md" > Examples</ span >
366
384
{ question ?. examples ?. map ( ( example , idx ) => (
@@ -394,7 +412,7 @@ const Question = ({
394
412
className = "mb-3"
395
413
>
396
414
{ showAnswer ? "Hide" : "Show" } Answer
397
- { showAnswer ? " ▼ " : " ▲ " }
415
+ { showAnswer ? " ▲ " : " ▼ " }
398
416
</ Button >
399
417
{ showAnswer && question ?. solution && (
400
418
< div className = "h-[50px] text-sm" >
0 commit comments