Files: ccc34dfd351fd863de680736e90b24f449a31a13 / js / calendar.js
893 bytesRaw
1 | document.addEventListener('dateUpdate', async function (event) { |
2 | const { year, month, date, week } = event.detail; |
3 | const selectedDate = new Date(year, month, date); |
4 | |
5 | const diff = ((new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), 0) - selectedDate)/86400000); |
6 | const num = Math.abs(diff).toFixed(); |
7 | let calc; |
8 | |
9 | diff < 0 ? calc = `In ${num} Day${num>1?'s':''}.` : diff == 0 ? calc = `Today.`: calc = `${num} Day${num>1?'s':''} ago.` |
10 | |
11 | const appointments = await window.letnice.appointments.getByDate(year, month, date); |
12 | const appointmentsHtml = !appointments |
13 | ? [] |
14 | : appointments.map(appointment => ` |
15 | - ${appointment.label} |
16 | `); |
17 | |
18 | document.dispatchEvent(new CustomEvent('footerChange', { |
19 | detail: ` |
20 | ${monthNames[month]} ${date}, ${dayNames[week]}. ${calc} |
21 | <br /> |
22 | ${appointmentsHtml.join('')} |
23 | ` |
24 | })); |
25 | }); |
Built with git-ssb-web