-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (29 loc) · 1.06 KB
/
index.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
import { createEvent } from "./events.js";
const upcoming = document.getElementById("upcoming-events");
const past = document.getElementById("past-events");
const soon = document.getElementById("soon");
const timeNow = new Date();
fetch("events.json")
.then((res) => res.text())
.then((text) => {
const events = JSON.parse(text);
events.forEach(event => {
const eventTime = new Date(event.time);
const eventListing = createEvent(event);
if (eventTime >= timeNow) {
const eventButton = document.createElement('button');
const eventLink = document.createElement('a');
eventButton.className = "main-button";
eventButton.innerHTML = "Learn More";
eventLink.href = event.facebookLink;
eventLink.appendChild(eventButton);
eventListing.appendChild(eventLink);
upcoming.insertBefore(eventListing, soon);
} else {
if (past.childElementCount < 3){
past.appendChild(eventListing);
}
}
});
})
.catch((e) => console.error(e));