mirror of
http://nostr-git-proxy.forgejo.svc.cluster.local/git/45387ca441053e230b2126802005eb03767ab59d84555e8bac86b6e7def14e27/myadhd
synced 2026-09-23 20:23:10 +00:00
feat: implement Accomplishments Done-Wall and IndexedDB datastore for task completion tracing
This commit is contained in:
parent
9b8f00a985
commit
2db8a05a5e
4 changed files with 183 additions and 0 deletions
|
|
@ -278,6 +278,24 @@
|
|||
</div>
|
||||
</section>
|
||||
|
||||
<section id="done" class="tool" role="tabpanel" aria-labelledby="tab-done" hidden>
|
||||
<div class="tool-head">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; width: 100%;">
|
||||
<div>
|
||||
<h1>Done-Wall</h1>
|
||||
<p class="sub">Everything you've finished, stored securely in your browser cache.</p>
|
||||
</div>
|
||||
<button class="btn ghost" id="done-clear" style="margin-left: 1rem;">Clear History</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<ul id="done-list" class="done-items" role="list" style="list-style: none; padding: 0; margin: 0;"></ul>
|
||||
<div id="done-empty" class="tiny" style="text-align: center; padding: 2rem 0; opacity: 0.7;">
|
||||
No tasks recorded yet. Complete something in the 'One Thing' tab to see it here!
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
|
||||
<!-- Celebration canvas (confetti) -->
|
||||
|
|
@ -352,6 +370,8 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/store.js" defer></script>
|
||||
<script src="/static/done.js" defer></script>
|
||||
<script src="/static/app.js" defer></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
90
site/static/done.js
Normal file
90
site/static/done.js
Normal file
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
65
site/static/store.js
Normal file
65
site/static/store.js
Normal file
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
};
|
||||
Loading…
Reference in a new issue