Reformate
This commit is contained in:
parent
4b2426960b
commit
8ed74bf3ec
1 changed files with 23 additions and 21 deletions
|
@ -23,13 +23,13 @@ const calendars = {
|
|||
w442JdS5AaQ6czrP: {
|
||||
cloud: clouds.ELEVES_ENS,
|
||||
name: "Écriv'ENS",
|
||||
color: null,
|
||||
color: null
|
||||
}
|
||||
}
|
||||
|
||||
const calendarsByName = Object.fromEntries(
|
||||
Object.entries(calendars).map(([id, {name}]) => ([name, id]))
|
||||
);
|
||||
Object.entries(calendars).map(([id, { name }]) => [name, id])
|
||||
)
|
||||
|
||||
export const calendarTree = {
|
||||
'Clubs COF': {
|
||||
|
@ -49,16 +49,19 @@ export const calendarTree = {
|
|||
|
||||
const calendarIds = Object.keys(calendars)
|
||||
|
||||
function mkCalendarUrl(id, { cloud }, extra={}) {
|
||||
return `/cal/${cloud}/${id}/?` + new URLSearchParams({
|
||||
...extra,
|
||||
export: true,
|
||||
expand: true,
|
||||
accept: 'jcal'
|
||||
});
|
||||
function mkCalendarUrl(id, { cloud }, extra = {}) {
|
||||
return (
|
||||
`/cal/${cloud}/${id}/?` +
|
||||
new URLSearchParams({
|
||||
...extra,
|
||||
export: true,
|
||||
expand: true,
|
||||
accept: 'jcal'
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
function fetchCalendar(id, cal, extra={}) {
|
||||
function fetchCalendar(id, cal, extra = {}) {
|
||||
return fetch(mkCalendarUrl(id, cal, extra), { credentials: 'omit' })
|
||||
.then(resp => resp.json())
|
||||
.catch(err => console.error(err))
|
||||
|
@ -133,28 +136,27 @@ function mkEventsFromCalendar(id, cal) {
|
|||
}
|
||||
|
||||
export function mkSource(name) {
|
||||
const calendarId = calendarsByName[name];
|
||||
if (!calendarId) return null;
|
||||
const calendar = calendars[calendarId];
|
||||
const calendarId = calendarsByName[name]
|
||||
if (!calendarId) return null
|
||||
const calendar = calendars[calendarId]
|
||||
|
||||
return {
|
||||
id: name,
|
||||
...(calendar?.meta || {}),
|
||||
success: calendarData => {
|
||||
if (calendarData[0] !== 'vcalendar') return;
|
||||
const cal = new Calendar(calendarId, calendarData);
|
||||
return cal.events.map(fcEventFromjCalEvent(cal));
|
||||
if (calendarData[0] !== 'vcalendar') return
|
||||
const cal = new Calendar(calendarId, calendarData)
|
||||
return cal.events.map(fcEventFromjCalEvent(cal))
|
||||
},
|
||||
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) => {
|
||||
const { start, end } = info;
|
||||
const { start, end } = info
|
||||
fetchCalendar(calendarId, calendar, {
|
||||
start: start.valueOf() / 1000,
|
||||
end: end.valueOf() / 1000
|
||||
})
|
||||
.then(successCallback, failureCallback);
|
||||
}).then(successCallback, failureCallback)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue