diff --git a/app/soapbox/features/chats/components/chat_window.js b/app/soapbox/features/chats/components/chat_window.js index 072aa0f5c..6c7cdf09a 100644 --- a/app/soapbox/features/chats/components/chat_window.js +++ b/app/soapbox/features/chats/components/chat_window.js @@ -59,12 +59,24 @@ class ChatWindow extends ImmutablePureComponent { this.setState({ content: e.target.value }); } + scrollToBottom = () => { + if (!this.messagesEnd) return; + this.messagesEnd.scrollIntoView({ behavior: 'smooth' }); + } + + setRef = (el) => this.messagesEnd = el; + componentDidMount() { const { dispatch, pane, chatMessages } = this.props; + this.scrollToBottom(); if (chatMessages && chatMessages.count() < 1) dispatch(fetchChatMessages(pane.get('chat_id'))); } + componentDidUpdate() { + this.scrollToBottom(); + } + render() { const { pane, idx, chatMessages } = this.props; const chat = pane.get('chat'); @@ -93,6 +105,7 @@ class ChatWindow extends ImmutablePureComponent { ))} +