Skip to content

Commit f8374dd

Browse files
committed
scroll to bottom
1 parent a91097b commit f8374dd

File tree

1 file changed

+15
-3
lines changed
  • services/static-webserver/client/source/class/osparc/conversation

1 file changed

+15
-3
lines changed

services/static-webserver/client/source/class/osparc/conversation/Conversation.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ qx.Class.define("osparc.conversation.Conversation", {
6464
__messages: null,
6565
__nextRequestParams: null,
6666
__messagesTitle: null,
67+
__messageScroll: null,
6768
__messagesList: null,
6869
__loadMoreMessages: null,
6970

@@ -147,10 +148,15 @@ qx.Class.define("osparc.conversation.Conversation", {
147148
this.__messagesTitle = new qx.ui.basic.Label();
148149
this._add(this.__messagesTitle);
149150

151+
// add spacer to keep the messages list at the bottom
152+
this._add(new qx.ui.core.Spacer(), {
153+
flex: 100 // high number to keep even a one message list at the bottom
154+
});
155+
150156
this.__messagesList = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({
151157
alignY: "middle"
152158
});
153-
const scrollView = new qx.ui.container.Scroll();
159+
const scrollView = this.__messageScroll = new qx.ui.container.Scroll();
154160
scrollView.add(this.__messagesList);
155161
this._add(scrollView, {
156162
flex: 1
@@ -246,9 +252,9 @@ qx.Class.define("osparc.conversation.Conversation", {
246252
return;
247253
}
248254

249-
// determine insertion index for most‐recent‐first order
255+
// determine insertion index for latest‐first order
250256
const newTime = new Date(message["created"]);
251-
let insertAt = this.__messages.findIndex(m => new Date(m["created"]) < newTime);
257+
let insertAt = this.__messages.findIndex(m => new Date(m["created"]) > newTime);
252258
if (insertAt === -1) {
253259
insertAt = this.__messages.length;
254260
}
@@ -273,6 +279,12 @@ qx.Class.define("osparc.conversation.Conversation", {
273279
this.__messagesList.addAt(control, insertAt);
274280
}
275281

282+
// scroll to bottom
283+
// add timeout to ensure the scroll happens after the UI is updated
284+
setTimeout(() => {
285+
this.__messageScroll.scrollToY(this.__messageScroll.getChildControl("pane").getScrollMaxY());
286+
}, 50);
287+
276288
this.__updateMessagesNumber();
277289
},
278290

0 commit comments

Comments
 (0)