From c63516d96291936fa8739af4a4d5fb98c76cfc69 Mon Sep 17 00:00:00 2001 From: Thomas Rupprecht Date: Mon, 20 Apr 2020 19:29:10 +0200 Subject: [PATCH] fix dates if no date is found --- background/index.js | 2 +- popup/index.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/background/index.js b/background/index.js index ce35152..5e654e9 100644 --- a/background/index.js +++ b/background/index.js @@ -2,7 +2,7 @@ const fetchJson = (url) => { return fetch(url).then((response) => (response.json())); }; -const fetchCalendar = (days = null) => { +const fetchCalendar = (days = 28) => { let url = Config.calenderUrl + '?o=json'; if (days) { url += '&r=' + days; diff --git a/popup/index.js b/popup/index.js index a18cbde..9b97493 100644 --- a/popup/index.js +++ b/popup/index.js @@ -20,12 +20,20 @@ browser.runtime.getBackgroundPage().then((page) => { }); const updateNextEvent = (nextEvents) => { - const nextEventDate = nextEvents[0].begin.substr(0, 10); - const nextEventDateEvents = nextEvents.filter((nextEvent) => (nextEvent.begin.startsWith(nextEventDate))); - const calendarElement = document.getElementById('calendar'); calendarElement.innerText = ''; + if (nextEvents.length === 0) { + const hintNode = document.createTextNode('Keine Termine in den nächsten 4 Wochen!'); + const strongElement = document.createElement('strong'); + strongElement.append(hintNode); + calendarElement.append(strongElement); + return; + } + + const nextEventDate = nextEvents[0].begin.substr(0, 10); + const nextEventDateEvents = nextEvents.filter((nextEvent) => (nextEvent.begin.startsWith(nextEventDate))); + nextEventDateEvents.forEach((nextEventDateEvent) => { const divElement = document.createElement('div'); divElement.innerHTML = 'Clock';