Online Homework Planner with AI Reminders

Online Homework Planner

Organize your assignments and never miss a deadline.

Add New Homework

Smart Reminders

Your Homework List

No homework tasks yet. Add one to get started!

`; } else { sortedTasks.forEach(task => { const taskCard = document.createElement('div'); taskCard.className = `task-card p-4 border-l-4 rounded-r-lg bg-white shadow-sm flex items-start gap-4 ${task.completed ? 'completed' : ''} new-task-animation`; taskCard.style.borderColor = getPriorityColor(task.priority); taskCard.dataset.id = task.id; const dueDate = dayjs(task.dueDate); const isOverdue = !task.completed && dueDate.isBefore(dayjs(), 'day'); taskCard.innerHTML = `

${task.subject}

${task.description}

Due: ${dueDate.format('MMMM D, YYYY')} (${dueDate.fromNow()})
`; taskListContainer.appendChild(taskCard); }); } updateAIReminders(); }; const getPriorityColor = (priority) => { switch (priority) { case '3': return '#ef4444'; // red-500 case '2': return '#f97316'; // orange-500 case '1': return '#3b82f6'; // blue-500 default: return '#6b7280'; // gray-500 } }; const updateAIReminders = () => { if (!aiRemindersContainer) return; aiRemindersContainer.innerHTML = ''; const upcomingTasks = tasks.filter(t => !t.completed) .sort((a, b) => new Date(a.dueDate) - new Date(b.dueDate)); if (upcomingTasks.length === 0) { aiRemindersContainer.innerHTML = `

🎉 All caught up! No pending homework.

`; return; } // Reminder 1: Most urgent task const mostUrgent = upcomingTasks[0]; const urgentDueDate = dayjs(mostUrgent.dueDate); const isUrgentOverdue = urgentDueDate.isBefore(dayjs(), 'day'); aiRemindersContainer.innerHTML += `
Next Up: ${mostUrgent.subject} is due ${urgentDueDate.fromNow()}. ${isUrgentOverdue ? 'It is overdue!' : ''}
`; // Reminder 2: High priority tasks const highPriority = upcomingTasks.filter(t => t.priority === '3'); if (highPriority.length > 0) { aiRemindersContainer.innerHTML += `
Heads Up: You have ${highPriority.length} high-priority task${highPriority.length > 1 ? 's' : ''} pending.
`; } }; const handleFormSubmit = (e) => { e.preventDefault(); const id = taskIdInput.value; const taskData = { subject: taskSubject.value, description: taskDescription.value, dueDate: taskDueDate.value, priority: taskPriority.value, completed: false }; if (id) { // Editing existing task const taskIndex = tasks.findIndex(t => t.id == id); if (taskIndex > -1) { tasks[taskIndex] = { ...tasks[taskIndex], ...taskData }; } } else { // Adding new task taskData.id = Date.now(); tasks.push(taskData); } saveTasks(); renderTasks(); taskForm.reset(); resetFormState(); }; const handleTaskListClick = (e) => { const target = e.target.closest('button, input[type="checkbox"]'); if (!target) return; const taskCard = target.closest('.task-card'); const taskId = parseInt(taskCard.dataset.id); if (target.classList.contains('edit-btn')) { const task = tasks.find(t => t.id === taskId); if (task) { taskSubject.value = task.subject; taskDescription.value = task.description; taskDueDate.value = task.dueDate; taskPriority.value = task.priority; taskIdInput.value = task.id; submitBtn.textContent = 'Update Task'; cancelEditBtn.classList.remove('hidden'); taskSubject.focus(); } } else if (target.classList.contains('delete-btn')) { tasks = tasks.filter(t => t.id !== taskId); saveTasks(); renderTasks(); } else if (target.classList.contains('toggle-complete-btn')) { const taskIndex = tasks.findIndex(t => t.id === taskId); if (taskIndex > -1) { tasks[taskIndex].completed = target.checked; saveTasks(); renderTasks(); } } }; const resetFormState = () => { taskIdInput.value = ''; submitBtn.textContent = 'Add Task'; cancelEditBtn.classList.add('hidden'); taskForm.reset(); }; const generatePDF = () => { const container = getElement('homework-planner-container'); if (!container) return; // Create a temporary printable version const printableContent = document.createElement('div'); // Style it to be off-screen so it doesn't flash printableContent.style.position = 'absolute'; printableContent.style.left = '-9999px'; printableContent.style.width = '210mm'; // A4 width for better rendering printableContent.innerHTML += `

My Homework Schedule

Generated on: ${dayjs().format('MMMM D, YYYY')}

`; const table = document.createElement('table'); table.className = 'pdf-table'; table.innerHTML = ` Subject Task Due Date Priority Status ${tasks.map(task => ` ${task.subject} ${task.description} ${dayjs(task.dueDate).format('MMM D, YYYY')} ${{3: 'High', 2: 'Medium', 1: 'Low'}[task.priority]} ${task.completed ? 'Completed' : 'Pending'} `).join('')} `; printableContent.appendChild(table); // Temporarily append to the body for html2canvas to find it document.body.appendChild(printableContent); // Use html2canvas to render this temporary content html2canvas(printableContent, { scale: 2 }).then(canvas => { // Remove the temporary element from the DOM document.body.removeChild(printableContent); const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgWidth = canvas.width; const imgHeight = canvas.height; const ratio = imgWidth / imgHeight; const pdfImgWidth = pdfWidth - 20; // with margin const pdfImgHeight = pdfImgWidth / ratio; pdf.addImage(imgData, 'PNG', 10, 10, pdfImgWidth, pdfImgHeight); pdf.save('Homework_Schedule.pdf'); }).catch(err => { // Ensure cleanup even if there's an error if (document.body.contains(printableContent)) { document.body.removeChild(printableContent); } console.error("PDF generation failed:", err); }); }; // --- Event Listeners --- if (taskForm) taskForm.addEventListener('submit', handleFormSubmit); if (taskListContainer) taskListContainer.addEventListener('click', handleTaskListClick); if (cancelEditBtn) cancelEditBtn.addEventListener('click', resetFormState); if (sortTasksSelect) sortTasksSelect.addEventListener('change', renderTasks); if (downloadPdfBtn) downloadPdfBtn.addEventListener('click', generatePDF); // --- Initial Load --- loadTasks(); renderTasks(); });
Scroll to Top