Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 2ee3f6e

Browse files
#10 - Change order in which messages are displayed to display latest messages first
1 parent 4f1644f commit 2ee3f6e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ui/src/App.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,15 @@ class App extends Component {
111111
};
112112
ws.onmessage = (event) => {
113113
const msgJSON = JSON.parse(event.data);
114+
let messages;
114115
if (msgJSON.topic !== that.state.selectedTopic) return;
115116
if (msgJSON.full) {
116-
that.setState({ messages: msgJSON.messages, loading: false });
117+
messages = msgJSON.messages.reverse();
118+
that.setState({ messages, loading: false });
117119
} else {
118-
let messages = that.state.messages.concat(msgJSON.messages);
120+
messages = msgJSON.messages.concat(that.state.messages);
119121
const maxCount = defaultMsgCount + that.state.extraMsgCount;
120-
if (messages.length > maxCount) messages = messages.slice(messages.length - maxCount);
122+
if (messages.length > maxCount) messages = messages.slice(0, maxCount);
121123
that.setState({ messages });
122124
}
123125
};

0 commit comments

Comments
 (0)