Skip to content

Commit b6ebcc5

Browse files
committed
Fix scroll position when pagination
1 parent 4571050 commit b6ebcc5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

frontend/src/app/collaboration/components/question.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,22 @@ const Question = ({
117117
}, [collaboratorId]);
118118

119119
useEffect(() => {
120+
const scrollToPercentage = (percentage: number) => {
121+
if (chatLogsListRef.current && hasMoreMessages.current) {
122+
const chatContainer = chatLogsListRef.current;
123+
const targetPosition = chatContainer.scrollHeight * percentage;
124+
chatContainer.scrollTop = targetPosition - chatContainer.clientHeight;
125+
}
126+
};
127+
120128
const handleScroll = () => {
121129
if (chatLogsListRef.current && chatLogsListRef.current.scrollTop === 0) {
122-
fetchChatLogs();
130+
fetchChatLogs().then(() => {
131+
requestAnimationFrame(() => {
132+
const percentage = Math.min(1 - (chatLogsPage - 1) / chatLogsPage);
133+
scrollToPercentage(percentage);
134+
});
135+
});
123136
}
124137
};
125138

0 commit comments

Comments
 (0)