mirror of
http://nostr-git-proxy.forgejo.svc.cluster.local/git/45387ca441053e230b2126802005eb03767ab59d84555e8bac86b6e7def14e27/myadhd
synced 2026-09-23 20:23:10 +00:00
90 lines
2.9 KiB
JavaScript
90 lines
2.9 KiB
JavaScript
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();
|
|
}
|
|
});
|
|
});
|
|
});
|