Skip to content
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
2 changes: 1 addition & 1 deletion src/content-script/components/chat/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const Chat: React.FC<ReduxProps> = ({ chatEnabled, partyId, toggleChat, partyUse
</Flex>
<Brand headingProps={{ fontWeight: 600 }} />
</HeaderContainer>
<Flex flex={3} overflowY="scroll" padding={2}>
<Flex flex={3} overflowY="hidden" padding={2}>
<MessageList />
</Flex>
<MessageBar />
Expand Down
12 changes: 11 additions & 1 deletion src/content-script/components/message-list/message-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,19 @@ type ReduxProps = ConnectedProps<typeof connector>;
const MessageList: React.FC<ReduxProps> = ({ messages }) => {
const messageRefs = useRef({} as Record<number, HTMLDivElement | null>);

const isInViewport = (elem: HTMLDivElement | null) => {
const bounds = elem?.getBoundingClientRect();
if (!bounds) return true;
return (
bounds.top >= 0 &&
// using a magic number of 130
bounds.bottom <= (window.innerHeight || document.documentElement.clientHeight) - 130
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: could you put parenthesis around each conditional statement

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah no prob, like this?
(bounds.top >= 0) &&
(bounds.bottom <= (window.innerHeight || document.documentElement.clientHeight) - 130)

Copy link
Collaborator

Choose a reason for hiding this comment

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

yup!

);
};

useEffect(() => {
const lastMessageId = messages[messages.length - 1]?.id;
if (lastMessageId) {
if (lastMessageId && isInViewport(messageRefs.current[lastMessageId])) {
messageRefs.current[lastMessageId]?.scrollIntoView(false);
}
}, [messages]);
Expand Down