From 43deb4eb3dcd796e8e6aaca66ef900447a5149fd Mon Sep 17 00:00:00 2001 From: David Peer Date: Sat, 20 Aug 2022 11:57:39 +0200 Subject: [PATCH] Minor improvements --- apps/bwclk/app.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/bwclk/app.js b/apps/bwclk/app.js index f6dbc0607..577014130 100644 --- a/apps/bwclk/app.js +++ b/apps/bwclk/app.js @@ -216,12 +216,10 @@ try{ /* * AGENDA MENU + * Note that we handle the agenda differently in order to hide old entries... */ var agendaIdx = 0; -var agenda = storage.readJSON("android.calendar.json"); -if(agenda !== undefined){ - agenda = agenda.sort((a,b)=>a.timestamp - b.timestamp); - +if(storage.readJSON("android.calendar.json") !== undefined){ function nextAgendaEntry(){ agendaIdx += 1; } @@ -233,15 +231,22 @@ if(agenda !== undefined){ menu.push([ function(){ var now = new Date(); - agenda = agenda.filter(ev=>ev.timestamp + ev.durationInSeconds > now/1000); + var agenda = storage.readJSON("android.calendar.json") + .filter(ev=>ev.timestamp + ev.durationInSeconds > now/1000) + .sort((a,b)=>a.timestamp - b.timestamp); + + if(agenda.length <= 0){ + return ["All done", imgAgenda()] + } agendaIdx = agendaIdx < 0 ? 0 : agendaIdx; agendaIdx = agendaIdx >= agenda.length ? agendaIdx -1 : agendaIdx; + var entry = agenda[agendaIdx]; var title = entry.title.slice(0,14); var date = new Date(entry.timestamp*1000); var dateStr = locale.date(date).replace(/\d\d\d\d/,""); - dateStr += entry.durationInSeconds < 86400 ? " - " + locale.time(date,1) : ""; + dateStr += entry.durationInSeconds < 86400 ? " / " + locale.time(date,1) : ""; return [title + "\n" + dateStr, imgAgenda(), () => nextAgendaEntry(), () => previousAgendaEntry(), null] },