Skip to content

Commit b9b53bc

Browse files
author
Philipp Heckel
committed
Fix Chrome/Firefox inconsistencies with sorting
1 parent a1385f6 commit b9b53bc

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

server/static/css/app.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,9 @@ li {
278278

279279
#detail #detailMain {
280280
max-width: 900px;
281-
margin: 0 auto 50px auto;
281+
margin: 0 auto;
282282
position: relative; /* required for close button's "position: absolute" */
283+
padding-bottom: 50px; /* Chrome and Firefox behave differently regarding bottom margin */
283284
}
284285

285286
#detail #detailCloseButton {

server/static/js/app.js

+13-17
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const subscribeInternal = (topic, persist, delaySec) => {
7373
eventSource.onmessage = (e) => {
7474
const event = JSON.parse(e.data);
7575
topics[topic]['messages'].push(event);
76-
topics[topic]['messages'].sort((a, b) => { return a.time < b.time; }) // Newest first
76+
topics[topic]['messages'].sort((a, b) => { return a.time < b.time ? 1 : -1; }); // Newest first
7777
if (currentTopic === topic) {
7878
rerenderDetailView();
7979
}
@@ -123,7 +123,7 @@ const fetchCachedMessages = async (topic) => {
123123
const message = JSON.parse(line);
124124
topics[topic]['messages'].push(message);
125125
}
126-
topics[topic]['messages'].sort((a, b) => { return a.time < b.time; }) // Newest first
126+
topics[topic]['messages'].sort((a, b) => { return a.time < b.time ? 1 : -1; }); // Newest first
127127
};
128128

129129
const showDetail = (topic) => {
@@ -258,27 +258,23 @@ if (!window["Notification"] || !window["EventSource"]) {
258258
// Reset UI
259259
topicField.value = "";
260260

261-
// (Temporarily) subscribe topic if we navigated to /sometopic URL
262-
const match = location.pathname.match(/^\/([-_a-zA-Z0-9]{1,64})$/) // Regex must match Go & Android app!
263-
if (match) {
264-
currentTopic = match[1];
265-
subscribeInternal(currentTopic, false,0);
266-
}
267-
268261
// Restore topics
269-
const storedTopics = localStorage.getItem('topics');
262+
const storedTopics = JSON.parse(localStorage.getItem('topics') || "[]");
270263
if (storedTopics) {
271-
const storedTopicsArray = JSON.parse(storedTopics);
272-
storedTopicsArray.forEach((topic) => { subscribeInternal(topic, true, 0); });
273-
if (storedTopicsArray.length === 0) {
264+
storedTopics.forEach((topic) => { subscribeInternal(topic, true, 0); });
265+
if (storedTopics.length === 0) {
274266
topicsHeader.style.display = 'none';
275267
}
276-
if (currentTopic) {
277-
currentTopicUnsubscribeOnClose = !storedTopicsArray.includes(currentTopic);
278-
}
279268
} else {
280269
topicsHeader.style.display = 'none';
281-
if (currentTopic) {
270+
}
271+
272+
// (Temporarily) subscribe topic if we navigated to /sometopic URL
273+
const match = location.pathname.match(/^\/([-_a-zA-Z0-9]{1,64})$/) // Regex must match Go & Android app!
274+
if (match) {
275+
currentTopic = match[1];
276+
if (!storedTopics.includes(currentTopic)) {
277+
subscribeInternal(currentTopic, false,0);
282278
currentTopicUnsubscribeOnClose = true;
283279
}
284280
}

0 commit comments

Comments
 (0)