From 2db8a05a5e6323545c261e6f3c27d37fecdb49ee Mon Sep 17 00:00:00 2001 From: djg Date: Wed, 23 Sep 2026 17:09:19 +0000 Subject: [PATCH] feat: implement Accomplishments Done-Wall and IndexedDB datastore for task completion tracing --- site/index.html | 20 ++++++++++ site/static/app.js | 8 ++++ site/static/done.js | 90 ++++++++++++++++++++++++++++++++++++++++++++ site/static/store.js | 65 ++++++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 site/static/done.js create mode 100644 site/static/store.js diff --git a/site/index.html b/site/index.html index b522b07..4ff0d9b 100644 --- a/site/index.html +++ b/site/index.html @@ -278,6 +278,24 @@ + + @@ -352,6 +370,8 @@ + + diff --git a/site/static/app.js b/site/static/app.js index 4d15e13..67a625e 100644 --- a/site/static/app.js +++ b/site/static/app.js @@ -676,8 +676,15 @@ $('#now-input').focus(); }); + function handleNewDoneTasks(taskString) { + if (window.dbRecordTask && taskString) { + window.dbRecordTask(taskString).then(() => { if (window.renderDoneWall) window.renderDoneWall(); }).catch(() => {}); + } + } + $('#now-done').addEventListener('click', function () { var nowData = store('now'); + var taskText = $('#now-text').textContent || (nowData && nowData.text) || ''; tickSound(); // If from breaker, mark that step done if (nowData && nowData.fromBreaker && typeof nowData.stepIndex === 'number') { @@ -688,6 +695,7 @@ breakerRender(); } } + handleNewDoneTasks(taskText); localStorage.removeItem('myadhd.now'); // Check if there's a next step from breaker var b2 = store(breakerKey); diff --git a/site/static/done.js b/site/static/done.js new file mode 100644 index 0000000..32e57a0 --- /dev/null +++ b/site/static/done.js @@ -0,0 +1,90 @@ +window.renderDoneWall = function() { + if (!window.dbGetAllTasks) return; + window.dbGetAllTasks().then(tasks => { + var list = document.querySelector('#done-list'); + var empty = document.querySelector('#done-empty'); + if (!list || !empty) return; + + if (tasks.length === 0) { + list.innerHTML = ''; + empty.hidden = false; + return; + } + empty.hidden = true; + list.innerHTML = ''; + + // Group by Date string (local date) + const groups = {}; + const todayStr = new Date().toDateString(); + + tasks.forEach(t => { + let d = new Date(t.completedAt); + let dStr = d.toDateString(); + if (dStr === todayStr) dStr = "Today"; + else if (dStr === new Date(Date.now() - 86400000).toDateString()) dStr = "Yesterday"; + else dStr = d.toLocaleDateString(undefined, { weekday: 'long', month: 'short', day: 'numeric' }); + + if (!groups[dStr]) groups[dStr] = []; + groups[dStr].push(t); + }); + + Object.keys(groups).forEach(dateLabel => { + let head = document.createElement('h3'); + head.textContent = dateLabel; + head.style.marginTop = '1.5rem'; + head.style.marginBottom = '0.5rem'; + head.style.color = 'var(--text-muted)'; + list.appendChild(head); + + groups[dateLabel].forEach(task => { + let li = document.createElement('li'); + li.style.padding = '0.5rem 0'; + li.style.borderBottom = '1px solid var(--border)'; + + let row = document.createElement('div'); + row.style.display = 'flex'; + row.style.justifyContent = 'space-between'; + + let textSpan = document.createElement('span'); + textSpan.textContent = "✓ " + task.text; + textSpan.style.color = 'var(--primary)'; + + // Time + let timeSpan = document.createElement('span'); + let d = new Date(task.completedAt); + timeSpan.textContent = d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); + timeSpan.style.color = 'var(--text-muted)'; + timeSpan.style.fontSize = '0.85em'; + + row.appendChild(textSpan); + row.appendChild(timeSpan); + li.appendChild(row); + list.appendChild(li); + }); + }); + }).catch(e => console.error(e)); +}; + +document.addEventListener('DOMContentLoaded', () => { + var clearBtn = document.querySelector('#done-clear'); + if (clearBtn) { + clearBtn.addEventListener('click', () => { + if (window.confirm("Are you sure you want to clear your entire accomplishment history?")) { + if (window.dbClearTasks) { + window.dbClearTasks().then(() => { + if (window.renderDoneWall) window.renderDoneWall(); + }); + } + } + }); + } + + // Bind to tab switch + document.querySelectorAll('.tab').forEach(tab => { + tab.addEventListener('click', e => { + if (tab.dataset.tab === 'done') { + if (window.renderDoneWall) window.renderDoneWall(); + } + }); + }); +}); diff --git a/site/static/store.js b/site/static/store.js new file mode 100644 index 0000000..24de0ba --- /dev/null +++ b/site/static/store.js @@ -0,0 +1,65 @@ +const DB_NAME = 'MyADHDSyncDB'; +const DB_VERSION = 1; +const DONE_STORE_NAME = 'done_cache'; + +let db = null; + +function getStoreDB() { + return new Promise((resolve, reject) => { + if (db) return resolve(db); + const request = indexedDB.open(DB_NAME, DB_VERSION); + request.onupgradeneeded = (event) => { + const adb = event.target.result; + if (!adb.objectStoreNames.contains(DONE_STORE_NAME)) { + adb.createObjectStore(DONE_STORE_NAME, { keyPath: 'id', autoIncrement: true }); + } + }; + request.onsuccess = (event) => { + db = event.target.result; + resolve(db); + }; + request.onerror = (event) => reject(event.target.error); + }); +} + +window.dbRecordTask = function(text) { + return getStoreDB().then((db) => { + return new Promise((resolve, reject) => { + const tx = db.transaction(DONE_STORE_NAME, 'readwrite'); + const store = tx.objectStore(DONE_STORE_NAME); + const req = store.add({ + text: text, + completedAt: new Date().toISOString() + }); + req.onsuccess = () => resolve(); + req.onerror = () => reject(req.error); + }); + }); +}; + +window.dbGetAllTasks = function() { + return getStoreDB().then((db) => { + return new Promise((resolve, reject) => { + const tx = db.transaction(DONE_STORE_NAME, 'readonly'); + const store = tx.objectStore(DONE_STORE_NAME); + const req = store.getAll(); + req.onsuccess = () => { + const sorted = (req.result || []).sort((a,b) => new Date(b.completedAt) - new Date(a.completedAt)); + resolve(sorted); + }; + req.onerror = () => reject(req.error); + }); + }); +}; + +window.dbClearTasks = function() { + return getStoreDB().then((db) => { + return new Promise((resolve, reject) => { + const tx = db.transaction(DONE_STORE_NAME, 'readwrite'); + const store = tx.objectStore(DONE_STORE_NAME); + const req = store.clear(); + req.onsuccess = () => resolve(); + req.onerror = () => reject(req.error); + }); + }); +};