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: Update to scroll behavior and UX tweaks #77

Merged
merged 4 commits into from
Jan 2, 2025

Conversation

rijuma
Copy link
Member

@rijuma rijuma commented Dec 19, 2024

Ticket: COSMO-597🔒

Description

This PR changes the way the chat scroll behaves. Its default behavior to have a smooth scroll down whenever a new message appears causes a weird experience on opening with an existing chat history to smooth scroll all messages down each time it opens. These changes makes the first render to scroll instantly to the last message on open and then uses smooth scrolling on each new message.

Additionally, it tweaks the UI to make it closer to the original design and added some extra tweaks.

#Screenshots

Old UI

xpert-chat-before

New UI

xpert-chat-after

Note

Notice some UI improvements like using shadows at the top and bottom of the chat scroll list, the shadows now are cast over the messages rather than clipping behind them and updated some sizes and paddings to make it nicer to the eye.

Comment on lines -40 to -75
const chatboxContainerRef = useRef(null);

// this use effect is intended to scroll to the bottom of the chat window, in the case
// that a message is larger than the chat window height.
useEffect(() => {
const messageContainer = chatboxContainerRef.current;

if (messageContainer) {
const { scrollHeight, clientHeight } = messageContainer;
const maxScrollTop = scrollHeight - clientHeight;
const duration = 200;

if (maxScrollTop > 0) {
const startTime = Date.now();
const endTime = startTime + duration;

const scroll = () => {
const currentTime = Date.now();
const timeFraction = (currentTime - startTime) / duration;
const scrollTop = maxScrollTop * timeFraction;

messageContainer.scrollTo({
top: scrollTop,
behavior: 'smooth',
});

if (currentTime < endTime) {
requestAnimationFrame(scroll);
}
};

requestAnimationFrame(scroll);
}
}
}, [messageList, isOpen, apiError]);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scrolling behavior was moved to the ChatBox component directly refactored to be much simpler.

@rijuma rijuma force-pushed the rijuma/xpert-scroll-behavior-update branch from a3f8b00 to c2b0504 Compare December 23, 2024 13:08
@rijuma rijuma marked this pull request as ready for review December 23, 2024 13:10
Copy link
Member

@MichaelRoytman MichaelRoytman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you for making those UI tweaks - makes a big difference in how professional the chat looks.

src/components/Sidebar/Sidebar.scss Outdated Show resolved Hide resolved
src/components/MessageForm/MessageForm.scss Outdated Show resolved Hide resolved
@rijuma rijuma merged commit 375847b into main Jan 2, 2025
4 checks passed
@rijuma rijuma deleted the rijuma/xpert-scroll-behavior-update branch January 2, 2025 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants