Inject next space launch to events calendar
This commit is contained in:
parent
acb33bf5f2
commit
cd5aef5c23
2 changed files with 59 additions and 17 deletions
|
@ -1,7 +1,7 @@
|
||||||
import dateformat from 'dateformat';
|
import dateformat from 'dateformat';
|
||||||
import '../elements/time';
|
import '../elements/time';
|
||||||
|
|
||||||
function getEvents(number) {
|
function getEvents(number, callback) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const allEvents = window.c_base_events.concat(window.c_base_regulars, window.c_base_seminars);
|
const allEvents = window.c_base_events.concat(window.c_base_regulars, window.c_base_seminars);
|
||||||
const current = allEvents.filter((event) => {
|
const current = allEvents.filter((event) => {
|
||||||
|
@ -32,6 +32,33 @@ function getEvents(number) {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fetch('https://launchlibrary.net/1.3/launch/next/1')
|
||||||
|
.then(res => res.json())
|
||||||
|
.then((res) => {
|
||||||
|
const launches = res.launches.map((launch) => {
|
||||||
|
return {
|
||||||
|
allDay: false,
|
||||||
|
start: new Date(launch.windowstart).toISOString(),
|
||||||
|
end: new Date(launch.windowend).toISOString(),
|
||||||
|
title: launch.name,
|
||||||
|
id: launch.lsp.abbrev,
|
||||||
|
type: 'launch',
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const events = current.concat(upcoming, launches);
|
||||||
|
events.sort((a, b) => {
|
||||||
|
if (a.start < b.start) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (a.start > b.start) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
console.log(events.slice(0, number));
|
||||||
|
return callback(events.slice(0, number));
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
const events = current.concat(upcoming);
|
const events = current.concat(upcoming);
|
||||||
events.sort((a, b) => {
|
events.sort((a, b) => {
|
||||||
if (a.start < b.start) {
|
if (a.start < b.start) {
|
||||||
|
@ -42,7 +69,8 @@ function getEvents(number) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
return events.slice(0, number);
|
return callback(events.slice(0, number));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let prevDate = new Date();
|
let prevDate = new Date();
|
||||||
|
@ -80,8 +108,15 @@ function renderEvent(event, container) {
|
||||||
time.innerHTML = dateformat(startDate, timeFormat);
|
time.innerHTML = dateformat(startDate, timeFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof event.id === 'number') {
|
||||||
code.innerHTML = `C${pad(event.id)}`;
|
code.innerHTML = `C${pad(event.id)}`;
|
||||||
|
} else {
|
||||||
|
code.innerHTML = event.id;
|
||||||
|
}
|
||||||
destination.innerHTML = cleanTitle(event.title);
|
destination.innerHTML = cleanTitle(event.title);
|
||||||
|
if (event.type === 'launch') {
|
||||||
|
destination.classList.add('launch');
|
||||||
|
}
|
||||||
|
|
||||||
if (startDate.toDateString() !== prevDate.toDateString()) {
|
if (startDate.toDateString() !== prevDate.toDateString()) {
|
||||||
status.innerHTML = dateformat(startDate, 'dd.mm.');
|
status.innerHTML = dateformat(startDate, 'dd.mm.');
|
||||||
|
@ -106,11 +141,12 @@ function renderEvent(event, container) {
|
||||||
|
|
||||||
function render() {
|
function render() {
|
||||||
const table = document.getElementById('events');
|
const table = document.getElementById('events');
|
||||||
|
getEvents(17, (events) => {
|
||||||
while (table.firstChild) {
|
while (table.firstChild) {
|
||||||
table.removeChild(table.firstChild);
|
table.removeChild(table.firstChild);
|
||||||
}
|
}
|
||||||
const events = getEvents(17);
|
|
||||||
events.forEach(event => renderEvent(event, table));
|
events.forEach(event => renderEvent(event, table));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPageReady() {
|
function onPageReady() {
|
||||||
|
|
|
@ -38,9 +38,15 @@
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
#events td.destination.launch {
|
||||||
|
color: hsl(210, 98%, 36%);
|
||||||
|
}
|
||||||
#events tr.today td.destination {
|
#events tr.today td.destination {
|
||||||
color: hsl(35, 98%, 46%);
|
color: hsl(35, 98%, 46%);
|
||||||
}
|
}
|
||||||
|
#events tr.today td.destination.launch {
|
||||||
|
color: hsl(210, 98%, 46%);
|
||||||
|
}
|
||||||
#events td.code {
|
#events td.code {
|
||||||
font-family: 'ceva', sans-serif;
|
font-family: 'ceva', sans-serif;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue