Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Maintain Scroll Position When Closing a Thread #973

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/react/src/views/ChatBody/ChatBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,14 @@ const ChatBody = ({
};

useEffect(() => {
if (messageListRef.current) {
messageListRef.current.scrollTop = messageListRef.current.scrollHeight;
const lastMessage = messages[0];
if (
lastMessage &&
lastMessage.t !== "message_pinned"
) {
scrollToBottom();
}
}, [messages]);
}, [messages.length]);
Abbas-Askari marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
checkOverflow();
Expand Down
16 changes: 15 additions & 1 deletion packages/react/src/views/ChatHeader/ChatHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ const ChatHeader = ({

const closeThread = useMessageStore((state) => state.closeThread);

const handleCloseThread = useCallback(() => {
const threadMessageId = threadMainMessage?._id;
closeThread();
setTimeout(() => {
const element = document.getElementById(`ec-message-body-${threadMessageId}`);
if (element) {
element.scrollIntoView({
behavior: 'instant',
block: 'start',
});
}
}, 300);
}, [closeThread, threadMainMessage]);

const setShowMembers = useMemberStore((state) => state.setShowMembers);
const setShowSearch = useSearchMessageStore((state) => state.setShowSearch);
const setShowPinned = usePinnedMessageStore((state) => state.setShowPinned);
Expand Down Expand Up @@ -430,7 +444,7 @@ const ChatHeader = ({
{isThreadOpen && (
<DynamicHeader
title={threadMainMessage}
handleClose={closeThread}
handleClose={handleCloseThread}
iconName="arrow-back"
/>
)}
Expand Down