fix(js): replace deprecated substr() with substring() and add checks for promise results

This commit is contained in:
Thomas Rupprecht 2023-02-04 18:05:47 +01:00
parent 848e1abee4
commit a193a6923c
2 changed files with 5 additions and 4 deletions

View File

@ -53,9 +53,10 @@ async function fetchNewData() {
return;
}
try {
const result = await Promise.allSettled([fetchCalendar(), fetchSpaceApi()]);
const calendarJson = result[0].value;
const spaceApiJson = result[1].value;
const [resultCalendar, resultSpaceApi] = await Promise.allSettled([fetchCalendar(), fetchSpaceApi()]);
const calendarJson = (resultCalendar.status === 'fulfilled') ? resultCalendar.value : undefined;
const spaceApiJson = (resultSpaceApi.status === 'fulfilled') ? resultSpaceApi.value : undefined;
if (spaceApiJson) {
const now = new Date();

View File

@ -80,7 +80,7 @@ function updateNextEvent(nextEvents) {
strongElement.textContent = browser.i18n.getMessage('noEventsInNext4Weeks');
calendarElement.append(strongElement);
} else {
const nextEventDate = nextEvents[0].begin.substr(0, 10);
const nextEventDate = nextEvents[0].begin.substring(0, 10);
const nextEventDateEvents = nextEvents.filter((nextEvent) => (nextEvent.begin.startsWith(nextEventDate)));
nextEventDateEvents.forEach((nextEventDateEvent) => {