// ── Global tasks view ── import { $, esc, api } from './util.js'; import { state } from './state.js'; const overlay = $('tasks'); const btn = $('tasks-btn'); const closeBtn = $('tasks-close'); const statusFilter = $('tasks-status-filter'); const bucketFilter = $('tasks-bucket-filter'); const list = $('tasks-list'); const summary = $('tasks-summary'); const countBadge = $('tasks-open-count'); function collectTasks() { const showShopping = localStorage.getItem('hyprcrd-tasks-show-shopping') === '1'; const all = []; for (const card of state.cards) { if (!showShopping) { const tags = (card.tags || '').split(',').map(s => s.trim()); if (tags.includes('einkauf') || tags.includes('shopping')) continue; } const re = /- \[([ xX])\][ \t]*([^\n\r]*)/g; let m, idx = 0; while ((m = re.exec(card.body || '')) !== null) { all.push({ cardId: card.id, cardTitle: card.title || 'untitled', cardColor: card.color || '#94a3b8', bucketId: card.bucket_id, bucketName: card.bucket_name || '', done: m[1].toLowerCase() === 'x', text: (m[2] || '').trim() || '(empty task)', todoIndex: idx++ }); } } return all; } function filter(tasks) { const s = statusFilter?.value || 'open', b = bucketFilter?.value || ''; return tasks.filter(t => { if (s === 'open' && t.done) return false; if (s === 'done' && !t.done) return false; if (b === 'none') return !t.bucketId; if (b && t.bucketId != b) return false; return true; }); } export function refreshTasksView() { if (!countBadge) return; const tasks = collectTasks(); const open = tasks.filter(t => !t.done).length; countBadge.textContent = String(open); if (!overlay?.classList.contains('open') || !list) return; const filtered = filter(tasks); if (summary) summary.textContent = `open: ${open} | done: ${tasks.length - open} | showing: ${filtered.length}`; if (!filtered.length) { list.innerHTML = `
no tasks in this filter