-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogs.js
42 lines (35 loc) · 1.15 KB
/
logs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
getData();
const posts = [];
document.getElementById('time').addEventListener('click', event => {
sortData((a, b) => b.time - a.time);
});
function sortData(compare) {
for (let e of posts) {
e.elt.remove();
}
posts.sort(compare);
for (let e of posts) {
document.body.append(e.elt);
}
}
async function getData(){
const response = await fetch('/api');
const data = await response.json();
for(e of data){
const root = document.createElement('p');
const talk = document.createElement('div');
const geo = document.createElement('div');
const date = document.createElement('div');
const image = document.createElement('img');
talk.textContent = `User Said: ${e.userText}`;
geo.textContent = `${e.lat}°, ${e.lon}°`;
const dateString = new Date(e.timestamp).toLocaleString();
date.textContent = dateString;
image.src = e.imageBase64;
image.alt = "Picture of user from webcam";
root.append(talk, geo, date, image);
posts.push({ elt: root, time: e.timestamp });
document.body.append(root);
}
console.log(data);
}