-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalendar.js
34 lines (31 loc) · 1.25 KB
/
calendar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('fetch-user-data').addEventListener('click', fetchCalendar);
});
async function fetchCalendar() {
const username = document.getElementById('username').value;
if (!username) return;
let response;
try {
response = await fetch(`${baseURL}${username}/calendar`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const calendarData = await response.json();
displayCalendar(calendarData);
} catch (error) {
console.error('Error fetching calendar data:', error);
}
}
function displayCalendar(calendarData) {
const calendar = document.getElementById('submission-calendar');
calendar.innerHTML = '';
// Assume calendarData is a JSON object with date keys and submission counts as values
for (const date in calendarData) {
const count = calendarData[date];
const dateDiv = document.createElement('div');
dateDiv.classList.add('calendar-date');
dateDiv.textContent = `${date}: ${count} submissions`;
calendar.appendChild(dateDiv);
}
document.getElementById('calendar').classList.remove('hidden');
}