Study Group Management Tool
My Study Groups
Create a New Study Group
Find a Public Study Group
My Weekly Study Schedule
${group.topic}
`; dayCol.appendChild(lessonBlock); }); scheduleContainer.appendChild(dayCol); }); } // --- LOGIC FUNCTIONS --- function populateSelects() { groupDaySelect.innerHTML = daysOfWeek.map(d => ``).join(''); } function clearForm() { groupForm.reset(); groupIdInput.value = ''; formTitle.textContent = 'Create a New Study Group'; saveGroupBtn.textContent = 'Create Group'; } function handleFormSubmit(e) { e.preventDefault(); const id = groupIdInput.value ? parseInt(groupIdInput.value) : null; const newGroupData = { subject: groupSubjectInput.value, topic: groupTopicInput.value, day: groupDaySelect.value, time: groupTimeInput.value, duration: parseInt(groupDurationInput.value), isPublic: groupPublicCheckbox.checked, members: id ? allGroups.find(g=>g.id===id).members : ['user'] }; if (id) { // Update const index = allGroups.findIndex(g => g.id === id); allGroups[index] = { ...allGroups[index], ...newGroupData }; } else { // Add const newId = allGroups.length > 0 ? Math.max(...allGroups.map(g => g.id)) + 1 : 1; allGroups.push({ id: newId, ...newGroupData }); if(!myJoinedGroupIds.includes(newId)) myJoinedGroupIds.push(newId); } renderAll(); clearForm(); changeTab(null, 'dashboard'); } window.editGroup = (id) => { const group = allGroups.find(g => g.id === id); if (group) { groupIdInput.value = group.id; groupSubjectInput.value = group.subject; groupTopicInput.value = group.topic; groupDaySelect.value = group.day; groupTimeInput.value = group.time; groupDurationInput.value = group.duration; groupPublicCheckbox.checked = group.isPublic; formTitle.textContent = 'Edit Study Group'; saveGroupBtn.textContent = 'Save Changes'; changeTab(null, 'create-edit'); } } window.joinGroup = (id) => { if (!myJoinedGroupIds.includes(id)) { myJoinedGroupIds.push(id); allGroups.find(g => g.id === id).members.push('user'); renderAll(); } } window.leaveGroup = (id) => { myJoinedGroupIds = myJoinedGroupIds.filter(gid => gid !== id); const group = allGroups.find(g => g.id === id); if(group) { group.members = group.members.filter(m => m !== 'user'); } renderAll(); } function downloadPDF() { const { jsPDF } = window.jspdf; const pdfContentEl = document.getElementById('pdf-content'); html2canvas(pdfContentEl, { scale: 2 }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'landscape', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgProps = pdf.getImageProperties(imgData); const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 20, 20, pdfWidth - 40, pdfHeight - 40); pdf.save('My_Study_Schedule.pdf'); }); } function renderAll() { renderMyGroups(); renderPublicGroups(searchInput.value); renderSchedule(); } // --- TAB NAVIGATION --- window.changeTab = function(evt, tabName) { document.querySelectorAll(".tab-content").forEach(tc => tc.classList.remove('active')); document.querySelectorAll(".tab-button").forEach(tb => tb.classList.remove('active')); document.getElementById(tabName).classList.add('active'); const button = evt ? evt.currentTarget : document.querySelector(`.tab-button[onclick*="'${tabName}'"]`); if(button) button.classList.add('active'); currentTab = tabName; updateNavButtons(); if(tabName === 'schedule') renderSchedule(); } function updateNavButtons() { const currentIndex = tabs.indexOf(currentTab); prevBtn.disabled = currentIndex === 0; nextBtn.disabled = currentIndex === tabs.length - 1; prevBtn.classList.toggle('opacity-50', prevBtn.disabled); nextBtn.classList.toggle('opacity-50', nextBtn.disabled); } window.navigateTabs = function(direction) { const currentIndex = tabs.indexOf(currentTab); let newIndex; if (direction === 'next' && currentIndex < tabs.length - 1) newIndex = currentIndex + 1; else if (direction === 'prev' && currentIndex > 0) newIndex = currentIndex - 1; if (newIndex !== undefined) changeTab(null, tabs[newIndex]); } // --- EVENT LISTENERS --- groupForm.addEventListener('submit', handleFormSubmit); clearFormBtn.addEventListener('click', clearForm); searchInput.addEventListener('input', (e) => renderPublicGroups(e.target.value)); downloadPdfBtn.addEventListener('click', downloadPDF); // --- INITIALIZATION --- populateSelects(); renderAll(); updateNavButtons(); });