diff options
Diffstat (limited to 'static/dashboard.js')
| -rw-r--r-- | static/dashboard.js | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/static/dashboard.js b/static/dashboard.js index 91ab2ec..072dbe1 100644 --- a/static/dashboard.js +++ b/static/dashboard.js @@ -27,7 +27,7 @@ const RUNNING = { k1c: "K1C", sbbuilder: "build", obs: "OBS" }; // the running const G = { cpu: "", mem: "\u{f035b}", gpu: "\u{f08ae}", net: "\u{f04e1}", wifi: "", charging: "\u{f0084}", tux: "", clock: "", - todo: "\u{f0131}" }; + todo: "\u{f0131}", done: "\u{f0135}" }; const BATTERY = ["", "", "", "", ""]; // Nerd Font distro logos by os-release ID. const DISTRO = { @@ -147,7 +147,7 @@ function gestures(el, { tap, hold, swipe }) { el.addEventListener("pointerup", () => { const wasTap = timer != null, wasSwipe = sliding && dx > el.offsetWidth / 3; reset(); - if (wasSwipe) { el.style.transform = "translateX(110%)"; swipe(); } + if (wasSwipe) swipe(); else el.style.transform = ""; if (wasTap) tap(); }); @@ -330,15 +330,18 @@ export default { 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 {} + // exit: the chip's leaving animation; the row is redrawn once both it + // and the request are over, so the animation is never cut short. + const act = async (name, id, line, exit) => { + const post = fetch(`/api/todo/${name}`, { + method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id }) }) + .then((r) => r.ok, () => false); + const [ok] = await Promise.all([post, exit?.finished.catch(() => {})]); + if (ok && exit) { + try { drawTodo(await (await fetch("/api/todo")).json()); } catch {} + } if (!ok) { // back in place, red for a moment - line.classList.remove("gone"); + exit?.cancel(); line.style.transform = ""; line.classList.add("fail"); setTimeout(() => line.classList.remove("fail"), 1500); @@ -354,8 +357,20 @@ export default { 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) }); + // done: a green check, then the chip shrinks away + hold: () => { + line.querySelector(".nf").textContent = G.done; + line.classList.add("done"); + act("done", t.id, line, line.animate( + [{ opacity: 1, transform: "scale(1)", offset: 0.4 }, + { opacity: 0, transform: "scale(0.6)" }], + { duration: 650, easing: "ease-in", fill: "forwards" })); + }, + // snooze: the chip carries on to the right and fades + swipe: () => act("snooze", t.id, line, line.animate( + [{ transform: line.style.transform, opacity: 1 }, + { transform: "translateX(120%)", opacity: 0 }], + { duration: 300, easing: "ease-out", fill: "forwards" })) }); todo.append(line); } if (tasks.length > 3) { |
