diff options
Diffstat (limited to 'static')
| -rw-r--r-- | static/app.js | 2 | ||||
| -rw-r--r-- | static/dashboard.js | 106 | ||||
| -rw-r--r-- | static/deck.css | 16 |
3 files changed, 121 insertions, 3 deletions
diff --git a/static/app.js b/static/app.js index 3249d64..d8b7361 100644 --- a/static/app.js +++ b/static/app.js @@ -141,7 +141,7 @@ function mountTab(name, panel, section) { } // Modules with no panel file: dashboard.js draws them. -const DRAWN = ["stats", "tablet", "llm", "actions"]; +const DRAWN = ["stats", "tablet", "llm", "actions", "todo"]; async function boot() { const r = await fetch("/api/modules"); diff --git a/static/dashboard.js b/static/dashboard.js index 336ce2a..1f123a7 100644 --- a/static/dashboard.js +++ b/static/dashboard.js @@ -15,16 +15,19 @@ // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // The Dashboard tab: a top band of chips, music and spending always on, a -// row of chips for one to three busy modules, each opening its full slot. +// row of chips for one to three busy modules, each opening its full slot, +// and the Vikunja tasks due now, only while there are some. // The page keeps the trend history; the modules' APIs are the existing ones. import { offline } from "./offline.js"; +import { HOLD_MS, buzz } from "./hold.js"; export const HISTORY = 120; // trend samples: two minutes at 1 s const RUNNING = { k1c: "K1C", sbbuilder: "build", obs: "OBS" }; // the running row's order and chip labels const G = { cpu: "", mem: "\u{f035b}", gpu: "\u{f08ae}", net: "\u{f04e1}", - wifi: "", charging: "\u{f0084}", tux: "", clock: "" }; + wifi: "", charging: "\u{f0084}", tux: "", clock: "", + todo: "\u{f0131}" }; const BATTERY = ["", "", "", "", ""]; // Nerd Font distro logos by os-release ID. const DISTRO = { @@ -102,6 +105,51 @@ function marquee(el) { } } +// A todo's due label: "overdue 2d", "today 15:00", or "reminder" when it +// only has a reminder. +export function dueLabel(iso, now = new Date()) { + if (!iso) return "reminder"; + const due = new Date(iso); + if (due.toDateString() === now.toDateString() && due >= now) + return `today ${due.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", hourCycle: "h23" })}`; + const h = (now - due) / 3600000; + return h < 24 ? `overdue ${Math.max(1, Math.round(h))}h` : `overdue ${Math.floor(h / 24)}d`; +} + +// Tap, hold, or swipe left to right on one element. A swipe past a third +// of its width fires; a shorter one springs back. Moving cancels the hold. +function gestures(el, { tap, hold, swipe }) { + let x0 = null, dx = 0, timer = null, sliding = false; + const reset = () => { + clearTimeout(timer); + timer = null; x0 = null; sliding = false; + el.classList.remove("holding", "sliding"); + }; + el.addEventListener("pointerdown", (e) => { + x0 = e.clientX; dx = 0; + el.setPointerCapture(e.pointerId); + el.classList.add("holding"); + timer = setTimeout(() => { reset(); buzz(); hold(); }, HOLD_MS); + }); + el.addEventListener("pointermove", (e) => { + if (x0 == null) return; + dx = Math.max(0, e.clientX - x0); + if (!sliding && Math.abs(e.clientX - x0) > 12) { + clearTimeout(timer); timer = null; sliding = true; + el.classList.remove("holding"); el.classList.add("sliding"); + } + if (sliding) el.style.transform = `translateX(${dx}px)`; + }); + el.addEventListener("pointerup", () => { + const wasTap = timer != null, wasSwipe = sliding && dx > el.offsetWidth / 3; + reset(); + if (wasSwipe) { el.style.transform = "translateX(110%)"; swipe(); } + else el.style.transform = ""; + if (wasTap) tap(); + }); + el.addEventListener("pointercancel", () => { reset(); el.style.transform = ""; }); +} + const SKELETON = ` <svg class="dash-defs" width="0" height="0" aria-hidden="true"><defs> <linearGradient id="hyline" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="120" y2="0"><stop offset="0" style="stop-color:var(--udt-border-1)"/> @@ -135,6 +183,7 @@ const SKELETON = ` <section class="dash-mid"> <div class="dash-always"><div class="card dash-music"></div><div class="card dash-spend"></div></div> <div class="dash-running" hidden></div> + <div class="card dash-todo" hidden></div> </section>`; export default { @@ -261,6 +310,59 @@ export default { if (on.has("xbox")) poll("xbox", 30, (st) => { last.xbox = st; draw(); }); }); + // Vikunja tasks due now: tap opens one on the PC, hold marks it done, + // a swipe right snoozes it 30 min. Redrawn only when the list changes, + // and never under a finger. + const todo = $(".dash-todo"); + const drawTodo = (st) => { + const key = JSON.stringify(st); + if (todo._key === key || todo.querySelector(".holding, .sliding")) return; + todo._key = key; + const tasks = st.tasks ?? []; + todo.hidden = !tasks.length && !st.error; + todo.textContent = ""; + if (st.error) { + todo.innerHTML = `<div class="td err">Vikunja unreachable</div>`; + todo.firstChild.title = st.error; + return; + } + const act = async (name, id, line) => { + let ok = false; + try { + ok = (await fetch(`/api/todo/${name}`, { + method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id }) })).ok; + if (ok && name !== "open") drawTodo(await (await fetch("/api/todo")).json()); + } catch {} + if (!ok) { // back in place, red for a moment + line.classList.remove("gone"); + line.style.transform = ""; + line.classList.add("fail"); + setTimeout(() => line.classList.remove("fail"), 1500); + } + }; + for (const t of tasks.slice(0, 3)) { + const line = document.createElement("div"); + line.className = "td"; + line.innerHTML = `<i class="nf"></i><span class="tt"></span><span class="due"></span>`; + line.querySelector(".nf").textContent = G.todo; + line.querySelector(".tt").textContent = t.title; + const due = dueLabel(t.due); + line.querySelector(".due").textContent = due; + line.classList.toggle("late", due.startsWith("overdue")); + gestures(line, { tap: () => act("open", t.id, line), + hold: () => { line.classList.add("gone"); act("done", t.id, line); }, + swipe: () => act("snooze", t.id, line) }); + todo.append(line); + } + if (tasks.length > 3) { + const more = document.createElement("div"); + more.className = "td more"; + more.textContent = `+${tasks.length - 3} more`; + todo.append(more); + } + }; + if (on.has("todo")) poll("todo", 10, drawTodo); + // The running row: a chip per module, created now in RUNNING order and // shown while it is busy. A tap opens its full slot, and the module's // detail(state, el) when it has one, centred over the page; a tap diff --git a/static/deck.css b/static/deck.css index a11583a..c01b5e4 100644 --- a/static/deck.css +++ b/static/deck.css @@ -749,6 +749,22 @@ select { .dash .legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.75rem; color: var(--udt-subtext0); } .dash .legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; background: var(--c); } +/* Vikunja tasks due now: one line each, hidden when there are none. + touch-action none, so a swipe right reaches dashboard.js, not the page. */ +.dash-todo { flex: none; display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; overflow: hidden; } +.dash-todo .td { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px; + background: var(--udt-surface0); touch-action: none; user-select: none; cursor: pointer; + transition: transform .25s ease, opacity .25s ease, background-color .8s ease; } +.dash-todo .td.sliding { transition: none; } +.dash-todo .td.holding { background: color-mix(in srgb, var(--udt-green) 35%, var(--udt-surface0)); } +.dash-todo .td.gone { opacity: 0; transform: scale(.97); } +.dash-todo .td.fail { background: color-mix(in srgb, var(--udt-red) 35%, var(--udt-surface0)); } +.dash-todo .td .nf { color: var(--udt-accent); font-size: 1.1rem; } +.dash-todo .td .tt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.dash-todo .td .due { flex: none; font-size: 0.786rem; color: var(--udt-subtext0); } +.dash-todo .td.late .due { color: var(--udt-red); } +.dash-todo .td.more, .dash-todo .td.err { background: none; cursor: default; color: var(--udt-overlay1); font-size: 0.786rem; padding: 2px 10px; } + /* The running row: one to three chips in equal columns, each opening its slot (and detail) as a centred modal. A line too long for the slot slides to its end and back (dashboard.js sets --d and --t). */ |
