Filter out past base events

This commit is contained in:
Henri Bergius 2018-12-25 01:18:53 +01:00
parent a92c831bca
commit 8c1ac5f8cc

View file

@ -1,5 +1,5 @@
import dateformat from 'dateformat'; import dateformat from 'dateformat';
import baseevents from './c-base'; import cbaseevents from './c-base';
import '../elements/time'; import '../elements/time';
function sortEvents(a, b) { function sortEvents(a, b) {
@ -14,41 +14,48 @@ function sortEvents(a, b) {
function getEvents(number) { function getEvents(number) {
const now = new Date(); const now = new Date();
return fetch('http://c-flo.cbrp3.c-base.org/35c3/fahrplan') return Promise.resolve(cbaseevents)
.then(res => res.json()) .then(events => events.filter((e) => {
.then((res) => { const endDate = new Date(e.end);
// res.schedule.conference.days[0].rooms.Adams[0] if (endDate < now) {
const talks = []; return false;
res.schedule.conference.days.forEach((day) => { }
const dayEnd = new Date(day.day_end); return true;
if (dayEnd < now) { }))
// Already done with this day .then(baseevents => fetch('http://c-flo.cbrp3.c-base.org/35c3/fahrplan')
return; .then(res => res.json())
} .then((res) => {
Object.keys(day.rooms).forEach((room) => { // res.schedule.conference.days[0].rooms.Adams[0]
day.rooms[room].forEach((slot) => { const talks = [];
const start = new Date(slot.date); res.schedule.conference.days.forEach((day) => {
const [durationH, durationM] = slot.duration.split(':').map(val => parseInt(val, 10)); const dayEnd = new Date(day.day_end);
const end = new Date(slot.date); if (dayEnd < now) {
end.setHours(end.getHours() + durationH); // Already done with this day
end.setMinutes(end.getMinutes() + durationM); return;
if (end < now) { }
// This event is already over Object.keys(day.rooms).forEach((room) => {
return; day.rooms[room].forEach((slot) => {
} const start = new Date(slot.date);
talks.push({ const [durationH, durationM] = slot.duration.split(':').map(val => parseInt(val, 10));
allDay: false, const end = new Date(slot.date);
start: start.toISOString(), end.setHours(end.getHours() + durationH);
end: end.toISOString(), end.setMinutes(end.getMinutes() + durationM);
title: slot.title, if (end < now) {
id: room, // This event is already over
return;
}
talks.push({
allDay: false,
start: start.toISOString(),
end: end.toISOString(),
title: slot.title,
id: room,
});
}); });
}); });
}); });
}); })
return talks; .then(talks => baseevents.concat(talks)))
})
.then(talks => baseevents.concat(talks))
.then(talks => fetch('https://launchlibrary.net/1.3/launch/next/2') .then(talks => fetch('https://launchlibrary.net/1.3/launch/next/2')
.then(res => res.json()) .then(res => res.json())
.then((res) => { .then((res) => {
@ -67,7 +74,6 @@ function getEvents(number) {
return launches; return launches;
}) })
.then((launches) => { .then((launches) => {
console.log(launches, talks);
const allEvents = talks.concat(launches); const allEvents = talks.concat(launches);
allEvents.sort(sortEvents); allEvents.sort(sortEvents);
return allEvents.slice(0, number); return allEvents.slice(0, number);