Reformate

This commit is contained in:
Tom Hubrecht 2022-03-06 19:38:26 +01:00
parent 4b2426960b
commit 8ed74bf3ec

View file

@ -23,13 +23,13 @@ const calendars = {
w442JdS5AaQ6czrP: { w442JdS5AaQ6czrP: {
cloud: clouds.ELEVES_ENS, cloud: clouds.ELEVES_ENS,
name: "Écriv'ENS", name: "Écriv'ENS",
color: null, color: null
} }
} }
const calendarsByName = Object.fromEntries( const calendarsByName = Object.fromEntries(
Object.entries(calendars).map(([id, {name}]) => ([name, id])) Object.entries(calendars).map(([id, { name }]) => [name, id])
); )
export const calendarTree = { export const calendarTree = {
'Clubs COF': { 'Clubs COF': {
@ -49,16 +49,19 @@ export const calendarTree = {
const calendarIds = Object.keys(calendars) const calendarIds = Object.keys(calendars)
function mkCalendarUrl(id, { cloud }, extra={}) { function mkCalendarUrl(id, { cloud }, extra = {}) {
return `/cal/${cloud}/${id}/?` + new URLSearchParams({ return (
`/cal/${cloud}/${id}/?` +
new URLSearchParams({
...extra, ...extra,
export: true, export: true,
expand: true, expand: true,
accept: 'jcal' accept: 'jcal'
}); })
)
} }
function fetchCalendar(id, cal, extra={}) { function fetchCalendar(id, cal, extra = {}) {
return fetch(mkCalendarUrl(id, cal, extra), { credentials: 'omit' }) return fetch(mkCalendarUrl(id, cal, extra), { credentials: 'omit' })
.then(resp => resp.json()) .then(resp => resp.json())
.catch(err => console.error(err)) .catch(err => console.error(err))
@ -133,28 +136,27 @@ function mkEventsFromCalendar(id, cal) {
} }
export function mkSource(name) { export function mkSource(name) {
const calendarId = calendarsByName[name]; const calendarId = calendarsByName[name]
if (!calendarId) return null; if (!calendarId) return null
const calendar = calendars[calendarId]; const calendar = calendars[calendarId]
return { return {
id: name, id: name,
...(calendar?.meta || {}), ...(calendar?.meta || {}),
success: calendarData => { success: calendarData => {
if (calendarData[0] !== 'vcalendar') return; if (calendarData[0] !== 'vcalendar') return
const cal = new Calendar(calendarId, calendarData); const cal = new Calendar(calendarId, calendarData)
return cal.events.map(fcEventFromjCalEvent(cal)); return cal.events.map(fcEventFromjCalEvent(cal))
}, },
failure: error => { failure: error => {
console.error(`Fatal error during event source fetching of '${name}': ${error}`); console.error(`Fatal error during event source fetching of '${name}': ${error}`)
}, },
events: (info, successCallback, failureCallback) => { events: (info, successCallback, failureCallback) => {
const { start, end } = info; const { start, end } = info
fetchCalendar(calendarId, calendar, { fetchCalendar(calendarId, calendar, {
start: start.valueOf() / 1000, start: start.valueOf() / 1000,
end: end.valueOf() / 1000 end: end.valueOf() / 1000
}) }).then(successCallback, failureCallback)
.then(successCallback, failureCallback);
} }
} }
} }