Habit Formation Dashboard

Add New Habit

Manage Existing Habits

Date: ${new Date().toLocaleDateString('en-US')}

${habits.map(habit => { const stats = calculateStats(habit); return ``; }).join('')}
Habit Current Streak Longest Streak Completion Rate (30d)
${habit.name} ${stats.currentStreak} days ${stats.longestStreak} days ${stats.completionRate}%
`; pdfOutput.innerHTML = pdfContent; try { const canvas = await html2canvas(pdfOutput, { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'px', format: [canvas.width, canvas.height] }); pdf.addImage(imgData, 'PNG', 0, 0, canvas.width, canvas.height); pdf.save('habit-dashboard-summary.pdf'); } catch(error) { console.error("Error generating PDF: ", error); alert("An error occurred while generating the PDF."); } finally { pdfOutput.innerHTML = ''; } }; // --- TAB NAVIGATION LOGIC --- // window.hfd_changeTab = (event, tabName) => { tabContents.forEach(content => content.classList.remove('active')); tabs.forEach(tab => tab.classList.remove('active')); document.getElementById(tabName).classList.add('active'); event.currentTarget.classList.add('active'); updateNavButtons(); }; const updateNavButtons = () => { const activeTabIndex = Array.from(tabs).findIndex(tab => tab.classList.contains('active')); if (prevBtn) prevBtn.disabled = activeTabIndex === 0; if (nextBtn) nextBtn.disabled = activeTabIndex === tabs.length - 1; }; window.hfd_navigateTabs = (direction) => { const activeTabIndex = Array.from(tabs).findIndex(tab => tab.classList.contains('active')); let newIndex = activeTabIndex; if (direction === 'next' && activeTabIndex < tabs.length - 1) { newIndex++; } else if (direction === 'prev' && activeTabIndex > 0) { newIndex--; } tabs[newIndex].click(); }; // --- EVENT LISTENERS INITIALIZATION --- // if (addHabitBtn) addHabitBtn.addEventListener('click', handleAddHabit); if (newHabitInput) newHabitInput.addEventListener('keypress', (e) => { if(e.key === 'Enter') handleAddHabit(); }); if (dashboardGrid) dashboardGrid.addEventListener('click', handleDashboardClick); if (configList) configList.addEventListener('click', handleConfigClick); if (pdfDownloadBtn) pdfDownloadBtn.addEventListener('click', generatePDF); // --- INITIAL RENDER --- // renderAll(); });
Scroll to Top