Chats: improve scroll behavior
This commit is contained in:
parent
205078c865
commit
c94258dfb9
|
@ -61,7 +61,7 @@ class ChatWindow extends ImmutablePureComponent {
|
||||||
|
|
||||||
scrollToBottom = () => {
|
scrollToBottom = () => {
|
||||||
if (!this.messagesEnd) return;
|
if (!this.messagesEnd) return;
|
||||||
this.messagesEnd.scrollIntoView({ behavior: 'smooth' });
|
this.messagesEnd.scrollIntoView();
|
||||||
}
|
}
|
||||||
|
|
||||||
focusInput = () => {
|
focusInput = () => {
|
||||||
|
@ -69,20 +69,26 @@ class ChatWindow extends ImmutablePureComponent {
|
||||||
this.inputElem.focus();
|
this.inputElem.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
setMessageEndRef = (el) => this.messagesEnd = el;
|
setMessageEndRef = (el) => {
|
||||||
setInputRef = (el) => this.inputElem = el;
|
this.messagesEnd = el;
|
||||||
|
this.scrollToBottom();
|
||||||
|
};
|
||||||
|
|
||||||
|
setInputRef = (el) => {
|
||||||
|
const { pane } = this.props;
|
||||||
|
this.inputElem = el;
|
||||||
|
if (pane.get('state') === 'open') this.focusInput();
|
||||||
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { dispatch, pane, chatMessages } = this.props;
|
const { dispatch, pane, chatMessages } = this.props;
|
||||||
this.scrollToBottom();
|
|
||||||
if (chatMessages && chatMessages.count() < 1)
|
if (chatMessages && chatMessages.count() < 1)
|
||||||
dispatch(fetchChatMessages(pane.get('chat_id')));
|
dispatch(fetchChatMessages(pane.get('chat_id')));
|
||||||
if (pane.get('state') === 'open')
|
|
||||||
this.focusInput();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
this.scrollToBottom();
|
if (prevProps.chatMessages !== this.props.chatMessages)
|
||||||
|
this.scrollToBottom();
|
||||||
|
|
||||||
const oldState = prevProps.pane.get('state');
|
const oldState = prevProps.pane.get('state');
|
||||||
const newState = this.props.pane.get('state');
|
const newState = this.props.pane.get('state');
|
||||||
|
|
Loading…
Reference in New Issue