aboutsummaryrefslogtreecommitdiffstats
path: root/static/dashboard.js
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-30 11:13:47 +0100
committerDanilo M. <danix@danix.xyz>2026-11-30 11:13:47 +0100
commit41c503645122f3d2d79ea4a428d6eb72c399c5b5 (patch)
tree92dfb9879824a9d2d67de8b7262b348fa1303930 /static/dashboard.js
parent88f120cb544296f4c760546a204f1e2268a2e5dd (diff)
downloaddeck-it-41c503645122f3d2d79ea4a428d6eb72c399c5b5.tar.gz
deck-it-41c503645122f3d2d79ea4a428d6eb72c399c5b5.zip
feat(todo): Vikunja tasks due now on the Dashboard
A row under the music and spending cards lists the open Vikunja tasks that are due today or overdue, or whose reminder has passed, and is hidden when there are none. A task with a reminder still ahead is left out, so snoozing adds a reminder 30 min ahead and the task returns when it fires. Tap opens the task in the PC's browser, hold marks it done, a swipe right snoozes it. [todo] url points at Vikunja; the API token lives in ~/.config/deck-it/vikunja-token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'static/dashboard.js')
-rw-r--r--static/dashboard.js106
1 files changed, 104 insertions, 2 deletions
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