Browse Source

Allow specifying scroll behavior on initial chat history load

pull/1845/head
Gabe Kangas 3 years ago
parent
commit
dc4c905dd1
No known key found for this signature in database
GPG Key ID: 9A56337728BC81EA
  1. 2
      webroot/js/components/chat/chat.js
  2. 8
      webroot/js/utils/helpers.js

2
webroot/js/components/chat/chat.js

@ -187,7 +187,7 @@ export default class Chat extends Component { @@ -187,7 +187,7 @@ export default class Chat extends Component {
this.handleNetworkingError(`Fetch getChatHistory: ${error}`);
}
this.scrollToBottom();
jumpToBottom(this.scrollableMessagesContainer.current, 'instant');
}
receivedWebsocketMessage(message) {

8
webroot/js/utils/helpers.js

@ -24,15 +24,19 @@ export function clearLocalStorage(key) { @@ -24,15 +24,19 @@ export function clearLocalStorage(key) {
}
// jump down to the max height of a div, with a slight delay
export function jumpToBottom(element) {
export function jumpToBottom(element, behavior) {
if (!element) return;
if (!behavior) {
behavior = document.visibilityState === 'visible' ? 'smooth' : 'instant';
}
setTimeout(
() => {
element.scrollTo({
top: element.scrollHeight,
left: 0,
behavior: document.visibilityState === 'visible' ? 'smooth' : 'instant',
behavior: behavior,
});
},
50,

Loading…
Cancel
Save