forked from XimeX/usrspace-browser-addon
fix(js): replace deprecated substr() with substring() and add checks for promise results
This commit is contained in:
parent
848e1abee4
commit
a193a6923c
|
@ -53,9 +53,10 @@ async function fetchNewData() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const result = await Promise.allSettled([fetchCalendar(), fetchSpaceApi()]);
|
const [resultCalendar, resultSpaceApi] = await Promise.allSettled([fetchCalendar(), fetchSpaceApi()]);
|
||||||
const calendarJson = result[0].value;
|
|
||||||
const spaceApiJson = result[1].value;
|
const calendarJson = (resultCalendar.status === 'fulfilled') ? resultCalendar.value : undefined;
|
||||||
|
const spaceApiJson = (resultSpaceApi.status === 'fulfilled') ? resultSpaceApi.value : undefined;
|
||||||
|
|
||||||
if (spaceApiJson) {
|
if (spaceApiJson) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
|
@ -80,7 +80,7 @@ function updateNextEvent(nextEvents) {
|
||||||
strongElement.textContent = browser.i18n.getMessage('noEventsInNext4Weeks');
|
strongElement.textContent = browser.i18n.getMessage('noEventsInNext4Weeks');
|
||||||
calendarElement.append(strongElement);
|
calendarElement.append(strongElement);
|
||||||
} else {
|
} 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)));
|
const nextEventDateEvents = nextEvents.filter((nextEvent) => (nextEvent.begin.startsWith(nextEventDate)));
|
||||||
|
|
||||||
nextEventDateEvents.forEach((nextEventDateEvent) => {
|
nextEventDateEvents.forEach((nextEventDateEvent) => {
|
||||||
|
|
Loading…
Reference in a new issue