Spaces:
Sleeping
Sleeping
jacobinathanialpeterson
commited on
Commit
•
a898227
1
Parent(s):
ad43143
Update static/script.js
Browse files- static/script.js +19 -36
static/script.js
CHANGED
@@ -54,43 +54,26 @@ function getMessages(roomId=myRoomId, url="https://jacobinathanialpeterson-chatb
|
|
54 |
})
|
55 |
.then(response => { if (!response.ok) { throw new Error('Network response was not ok.') } return response.json() })
|
56 |
.then(data => {
|
57 |
-
if (data.message) {
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
75 |
}
|
76 |
-
// Get the keys of the object
|
77 |
-
const keys = Object.keys(data);
|
78 |
-
|
79 |
-
// Sort the keys based on their natural order
|
80 |
-
keys.sort((a, b) => {
|
81 |
-
// Extract numeric part of keys
|
82 |
-
const numA = parseInt(a.match(/\d+/)[0]);
|
83 |
-
const numB = parseInt(b.match(/\d+/)[0]);
|
84 |
-
return numA - numB;
|
85 |
-
});
|
86 |
-
|
87 |
-
// Create a new object with sorted keys
|
88 |
-
DATA = {};
|
89 |
-
keys.forEach(key => {
|
90 |
-
DATA[key] = data[key];
|
91 |
-
});
|
92 |
-
|
93 |
-
controller.abort();
|
94 |
})
|
95 |
.catch(error => { if (error.name === 'AbortError') { console.log('Fetch aborted:', error.message) } else { console.error('Error fetching data:', error.message) }});
|
96 |
}
|
|
|
54 |
})
|
55 |
.then(response => { if (!response.ok) { throw new Error('Network response was not ok.') } return response.json() })
|
56 |
.then(data => {
|
57 |
+
if (!data.message) {
|
58 |
+
// Get the keys of the object
|
59 |
+
const keys = Object.keys(data);
|
60 |
+
|
61 |
+
// Sort the keys based on their natural order
|
62 |
+
keys.sort((a, b) => {
|
63 |
+
// Extract numeric part of keys
|
64 |
+
const numA = parseInt(a.match(/\d+/)[0]);
|
65 |
+
const numB = parseInt(b.match(/\d+/)[0]);
|
66 |
+
return numA - numB;
|
67 |
+
});
|
68 |
+
|
69 |
+
// Create a new object with sorted keys
|
70 |
+
DATA = {};
|
71 |
+
keys.forEach(key => {
|
72 |
+
DATA[key] = data[key];
|
73 |
+
});
|
74 |
+
|
75 |
+
controller.abort();
|
76 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
})
|
78 |
.catch(error => { if (error.name === 'AbortError') { console.log('Fetch aborted:', error.message) } else { console.error('Error fetching data:', error.message) }});
|
79 |
}
|