Dairy Intolerance Tracker

Dairy Intolerance Tracker

Log your meals and symptoms to identify patterns.

Add a New Log

Symptoms Experienced

Connecting to database...

Mild: ${severityCounts.Mild}, Mod: ${severityCounts.Moderate}, Sev: ${severityCounts.Severe}

`; } // --- PDF Generation --- async function generatePdf() { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' }); // Header doc.setFont('Inter', 'bold'); doc.setFontSize(24); doc.setTextColor('#2563eb'); // blue-600 doc.text('Dairy Intolerance Log Report', 105, 20, { align: 'center' }); doc.setFont('Inter', 'normal'); doc.setFontSize(10); doc.setTextColor('#64748b'); // slate-500 doc.text(`Report generated on: ${new Date().toLocaleDateString('en-US')}`, 105, 27, { align: 'center' }); doc.setLineWidth(0.5); doc.setDrawColor('#93c5fd'); // blue-300 doc.line(20, 35, 190, 35); // Summary Section doc.setFont('Inter', 'bold'); doc.setFontSize(16); doc.setTextColor('#1d4ed8'); // blue-700 doc.text('Summary', 20, 45); const summaryEl = summaryContent.cloneNode(true); const summaryText = Array.from(summaryEl.querySelectorAll('p')).map(p => p.textContent).join('\n'); doc.setFont('Inter', 'normal'); doc.setFontSize(11); doc.setTextColor('#334155'); // slate-700 doc.text(summaryText.replace(/:/g, ':\n').replace(/,/g, '\n'), 22, 53, { lineHeightFactor: 1.5 }); // Log Entries Section let startY = 100; doc.setFont('Inter', 'bold'); doc.setFontSize(16); doc.setTextColor('#1d4ed8'); // blue-700 doc.text('Detailed Log Entries', 20, startY); startY += 8; userLogs.slice(0, 15).forEach(log => { // Limit to 15 entries for PDF space if (startY > 270) return; // Stop if we run out of page const consumedDate = log.consumedAt.toDate(); doc.setFillColor(241, 245, 249); // slate-100 doc.rect(20, startY-5, 170, 22, 'F'); doc.setFont('Inter', 'bold'); doc.setFontSize(12); doc.setTextColor('#1e293b'); // slate-800 doc.text(log.dairyItem, 22, startY); doc.setFont('Inter', 'normal'); doc.setFontSize(9); doc.setTextColor('#64748b'); // slate-500 doc.text(consumedDate.toLocaleString(), 110, startY); startY += 7; doc.setFontSize(10); doc.setTextColor('#334155'); // slate-700 doc.text(`Symptoms: ${log.selectedSymptoms.join(', ') || 'None'} (Severity: ${log.severity})`, 22, startY); startY += 15; }); doc.save('Dairy_Intolerance_Report.pdf'); } // --- Event Listeners --- Object.keys(tabs).forEach(tabName => { if (tabs[tabName]) tabs[tabName].addEventListener('click', () => setActiveTab(tabName)); }); if (logForm) logForm.addEventListener('submit', handleFormSubmit); if (downloadPdfBtn) downloadPdfBtn.addEventListener('click', generatePdf); if (logContainer) { logContainer.addEventListener('click', (e) => { if (e.target.classList.contains('delete-btn')) { const logId = e.target.dataset.id; deleteLog(logId); } }); } // --- Initial Load --- populateSymptoms(); setActiveTab('logEntry');
Scroll to Top