Recovery Journal
A tool to track progress, prompts, and goals.
Journal Dashboard
Mood Summary
My Journal Entries
New Journal Entry
Goals & Milestones
Track your recovery goals. Check them off as you complete them.
Journal Configuration
Custom Journal Prompts
Add or remove prompts that will appear on the "New Entry" form.
Data Management
No goals set yet. Add one above to get started.
`; return; } goalsList.innerHTML = recoveryGoals.map((goal, index) => `
${prompt}
`).join('');
// Attach listeners
promptsList.querySelectorAll('.rjg-prompt-delete').forEach(btn => {
btn.addEventListener('click', (e) => {
const index = parseInt(e.target.dataset.index, 10);
journalPrompts.splice(index, 1);
renderConfig();
renderNewEntryForm(); // Update the entry form
});
});
}
function handleAddPrompt(e) {
e.preventDefault();
const text = newPromptInput.value.trim();
if (text && !journalPrompts.includes(text)) {
journalPrompts.push(text);
newPromptInput.value = '';
renderConfig();
renderNewEntryForm(); // Update the entry form
}
}
// --- Data & PDF ---
function loadSampleData() {
journalPrompts = [
"What was my biggest challenge today?",
"What am I grateful for today?",
"What is one small victory I achieved?",
"How did I take care of myself today?"
];
recoveryGoals = [
{ id: 1, text: "Attend a support group meeting", complete: true },
{ id: 2, text: "Practice mindfulness for 10 minutes", complete: false },
{ id: 3, text: "Reach out to a friend in the US", complete: false }
];
journalEntries = [
{
id: 1, date: "2025-10-27", mood: "Good",
responses: [
{ prompt: "What was my biggest challenge today?", answer: "Waking up on time was tough, but I did it." },
{ prompt: "What am I grateful for today?", answer: "My friend in Chicago called." },
{ prompt: "What is one small victory I achieved?", answer: "I went for a 20-minute walk." },
{ prompt: "How did I take care of myself today?", answer: "Ate a healthy breakfast." }
], notes: "Felt pretty positive overall."
},
{
id: 2, date: "2025-10-28", mood: "Struggling",
responses: [
{ prompt: "What was my biggest challenge today?", answer: "Felt a lot of anxiety about work." },
{ prompt: "What am I grateful for today?", answer: "My family." },
{ prompt: "What is one small victory I achieved?", answer: "I still managed to get my main work task done." },
{ prompt: "How did I take care of myself today?", answer: "I used a breathing exercise." }
], notes: "Tough day, but I got through it."
}
];
renderNewEntryForm();
renderGoals();
renderConfig();
showTab(0);
}
async function downloadPDF() {
const pdfTarget = document.getElementById('rjg-pdf-target');
pdfTarget.classList.add('rjg-pdf-view');
try {
const canvas = await html2canvas(pdfTarget, {
scale: 2,
logging: false,
useCORS: true,
onclone: (doc) => {
// Ensure chart renders in PDF
const originalCanvas = moodChartCanvas;
const newCanvas = doc.getElementById('rjg-mood-chart');
if (newCanvas) {
newCanvas.getContext('2d').drawImage(originalCanvas, 0, 0);
}
}
});
const imgData = canvas.toDataURL('image/png');
const { jsPDF } = window.jspdf;
const pdf = new jsPDF('p', 'mm', 'a4');
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
const pageMargin = 15;
const contentWidth = pdfWidth - (pageMargin * 2);
const contentHeight = (canvas.height * contentWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', pageMargin, pageMargin, contentWidth, contentHeight);
pdf.save('Recovery_Journal.pdf');
} catch (error) {
console.error("Error generating PDF:", error);
} finally {
pdfTarget.classList.remove('rjg-pdf-view');
}
}
// --- 4. EVENT BINDING & INITIALIZATION ---
navTabs.forEach((tab, index) => {
tab.addEventListener('click', () => showTab(index));
});
entryForm.addEventListener('submit', handleSaveEntry);
addGoalForm.addEventListener('submit', handleAddGoal);
addPromptForm.addEventListener('submit', handleAddPrompt);
loadSampleBtn.addEventListener('click', loadSampleData);
pdfDownloadBtn.addEventListener('click', downloadPDF);
// Initial Load
loadSampleData();
showTab(0);
});
