Public: anyone can read this; the crew can change it.
small: Review answers to the keys S, D and T on the focused reminder #280
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/272-small-review-answers-to-the-keys-s-d-and → main 4 commits fork 3 threads · 3 unresolved
5 files
changed +57
−8
src/pages/review.ts +7 −5
| @@ -11,7 +11,7 @@ import type { Next } from "../coming.ts"; | ||
| 11 | 11 | import { BODY_MAX, EMAIL_MAX, PHONE_MAX, REASON_MAX, SUBJECT_MAX } from "../deals.ts"; |
| 12 | 12 | import { spoken } from "../dates.ts"; |
| 13 | 13 | import { PARTY_LABEL } from "../deadlines.ts"; |
| 14 | import { escape } from "../http.ts"; | |
| 14 | import { asset, escape } from "../http.ts"; | |
| 15 | 15 | import { heldFrom, momentLabel, type Draft } from "../reminders.ts"; |
| 16 | 16 | import type { Who } from "../who.ts"; |
| 17 | 17 | import { layout } from "./layout.ts"; |
| @@ -114,9 +114,10 @@ function form( | ||
| 114 | 114 | error?.field === field ? `<p class="conflict" role="alert"><b>${FIELD_LABEL[field]}:</b> ${escape(error.message)}</p>` : ""; |
| 115 | 115 | const invalid = (field: ReviewField): string => (error?.field === field ? ' aria-invalid="true"' : ""); |
| 116 | 116 | const skip = s.total - s.done > 1 ? reviewHref(s.q, s.at + 1, s.done) : ""; |
| 117 | return `<section class="card narrow"> | |
| 117 | return `<section class="card narrow" tabindex="0" data-keys aria-describedby="review-keys"> | |
| 118 | 118 | ${s.done === 0 && s.at === 0 ? "<p><b>Start here</b></p>\n " : ""}<p class="eyebrow">${s.position} of ${s.total}</p> |
| 119 | 119 | <h1>Review today's reminders</h1> |
| 120 | <p class="muted small" id="review-keys">Keys, with the card focused: <kbd>S</kbd> send · <kbd>D</kbd> don't send · <kbd>T</kbd> tomorrow. Typing in a box never triggers them.</p> | |
| 120 | 121 | <p><a href="/deals/${draft.deal_id}">${escape(draft.address)}</a></p> |
| 121 | 122 | <p><b>${escape(draft.label)}</b> <span class="muted">· ${escape(spoken(draft.due))} · ${escape(momentLabel(draft.moment, draft.lead_days))}${draft.held === null ? "" : ` · ${escape(heldFrom(draft.held))}`}</span></p> |
| 122 | 123 | <p>To <b>${escape(draft.party_name)}</b> <span class="muted">· ${escape(PARTY_LABEL[draft.party_role])}${[draft.email, draft.phone].filter((v) => v !== "").map((v) => ` · ${escape(v)}`).join("") || (draft.contact === "" ? "" : ` · ${escape(draft.contact)}`)}</span></p> |
| @@ -127,15 +128,16 @@ function form( | ||
| 127 | 128 | <label>Subject<input class="input" name="subject" value="${escape(typed.subject)}" maxlength="${SUBJECT_MAX}" required${invalid("subject")}></label> |
| 128 | 129 | ${problem("body")} |
| 129 | 130 | <label>Message<textarea class="input" name="body" rows="9" maxlength="${BODY_MAX}" required${invalid("body")}>${escape(typed.body)}</textarea></label> |
| 130 | <button class="button">Send</button> | |
| 131 | <button class="button" data-key="s" aria-keyshortcuts="S">Send</button> | |
| 131 | 132 | ${draft.contact === "" ? '<span class="muted small">No contact on file: Send records the approval and your Mail opens with no recipient.</span>' : ""} |
| 132 | ${draft.moment === "status" ? "" : `<button class="button button-quiet" formaction="${REVIEW_PATH}/hold">Tomorrow</button>`} | |
| 133 | ${draft.moment === "status" ? "" : `<button class="button button-quiet" data-key="t" aria-keyshortcuts="T" formaction="${REVIEW_PATH}/hold">Tomorrow</button>`} | |
| 133 | 134 | </form> |
| 134 | 135 | <form class="move" method="post" action="${REVIEW_PATH}/decline">${hidden(keys)} |
| 135 | 136 | ${problem("reason")} |
| 136 | 137 | <label>Why not<input class="input" name="reason" value="${escape(typed.reason)}" maxlength="${REASON_MAX}" required placeholder="e.g. Buyer already confirmed by phone"${invalid("reason")}></label> |
| 137 | <button class="button button-quiet">Don't send</button> | |
| 138 | <button class="button button-quiet" data-key="d" aria-keyshortcuts="D">Don't send</button> | |
| 138 | 139 | </form> |
| 140 | <script type="module" src="${asset("review.js")}"></script> | |
| 139 | 141 | <p>${skip === "" ? "" : `<a class="button button-quiet" href="${escape(skip)}">Skip</a> `}${back}</p> |
| 140 | 142 | </section>`; |
| 141 | 143 | } |
src/review.test.ts +31
| @@ -55,6 +55,37 @@ test("the round's first draft says Start here, once; a skipped-to draft does not | ||
| 55 | 55 | expect(count(await get("/reminders/today?at=1"))).toBe(0); |
| 56 | 56 | }); |
| 57 | 57 | |
| 58 | test("Review answers to S, D and T on the focused card: a hint, real buttons, one small cached script", async () => { | |
| 59 | const page = await get("/reminders/today"); | |
| 60 | expect(page).toContain('id="review-keys"'); | |
| 61 | expect(page).toContain('aria-describedby="review-keys"'); | |
| 62 | expect(page).toMatch(/<button[^>]*data-key="s"[^>]*>Send<\/button>/); | |
| 63 | expect(page).toMatch(/<button[^>]*data-key="d"[^>]*>Don't send<\/button>/); | |
| 64 | expect(page).toMatch(/<button[^>]*data-key="t"[^>]*>Tomorrow<\/button>/); | |
| 65 | const src = /src="(\/static\/review\.js\?v=[0-9a-f]+)"/.exec(page)?.[1]; | |
| 66 | expect(src).toBeDefined(); | |
| 67 | const script = await fetch(base + src!); | |
| 68 | expect(script.headers.get("cache-control")).toContain("immutable"); | |
| 69 | const text = await script.text(); | |
| 70 | expect(text.length).toBeLessThan(1024); | |
| 71 | // Behaviour: run the handler against a stand-in card; odd keys must not throw, typing must not click. | |
| 72 | const clicked: string[] = []; | |
| 73 | let handler: (e: unknown) => void = () => {}; | |
| 74 | const button = (key: string) => ({ dataset: { key }, click: () => clicked.push(key) }); | |
| 75 | const card = { focus() {}, addEventListener: (_: string, h: typeof handler) => (handler = h), querySelectorAll: () => ["s", "d", "t"].map(button) }; | |
| 76 | (globalThis as { document?: unknown }).document = { querySelector: () => card }; | |
| 77 | new Function(text)(); | |
| 78 | const press = (key: string, inField = false) => handler({ key, target: { closest: () => inField }, preventDefault() {} }); | |
| 79 | for (const key of ['"', "\\", "]", "Enter"]) press(key); | |
| 80 | expect(clicked).toEqual([]); | |
| 81 | press("S", true); | |
| 82 | expect(clicked).toEqual([]); | |
| 83 | press("s"); | |
| 84 | press("D"); | |
| 85 | press("t"); | |
| 86 | expect(clicked).toEqual(["s", "d", "t"]); | |
| 87 | }); | |
| 88 | ||
| 58 | 89 | test("walking the queue visits the unsent drafts in the clock's order; Skip changes nothing", async () => { |
| 59 | 90 | const before = await get("/"); |
| 60 | 91 | const page = await get("/reminders/today"); |
src/sample.ts +5 −2
| @@ -430,8 +430,11 @@ function writeSamples(db: Database, on: string): void { | ||
| 430 | 430 | } |
| 431 | 431 | // The anniversary sample was finished on the day a year back, whichever business day its due falls on. |
| 432 | 432 | const finished = s.anniversary === undefined ? addDays(on, -1) : addDays(addDays(on, at.closing), -1); |
| 433 | for (const kind of s.done ?? []) | |
| 434 | db.query("UPDATE deadline SET done_at = min(date(due, '-1 day'), ?1) || ?2 WHERE deal_id = ?3 AND kind = ?4").run(finished, DONE_TIME, deal.id, kind); | |
| 433 | for (const kind of s.done ?? []) { | |
| 434 | // The anniversary sample's closing is stamped on its anniversary day, however far its due rolled back. | |
outdated
Out of scope for this pull and awkward: SQL assembled by a conditional template. Use two plain statements, or split this fix into its own pull. |
||
| 435 | if (s.anniversary !== undefined && kind === "closing") db.query("UPDATE deadline SET done_at = ?1 || ?2 WHERE deal_id = ?3 AND kind = ?4").run(finished, DONE_TIME, deal.id, kind); | |
| 436 | else db.query("UPDATE deadline SET done_at = min(date(due, '-1 day'), ?1) || ?2 WHERE deal_id = ?3 AND kind = ?4").run(finished, DONE_TIME, deal.id, kind); | |
| 437 | } | |
| 435 | 438 | for (const kind of s.waived ?? []) |
| 436 | 439 | db.query("UPDATE deadline SET waived_at = ?1, waived_by = ?2 WHERE deal_id = ?3 AND kind = ?4").run(`${addDays(on, -1)}${DONE_TIME}`, SAMPLE.name, deal.id, kind); |
| 437 | 440 | for (const [kind, note] of s.notes ?? []) |
src/week.appointment.test.ts +1 −1
| @@ -65,7 +65,7 @@ test("a day's timed dates come first, earliest first, then the untimed in today' | ||
| 65 | 65 | setAppointment(db, alice, { id: dateOf(b, "walkthrough").id, time: "15:30" }); |
| 66 | 66 | const deals = listDeals(db, alice); |
| 67 | 67 | if (!deals.ok) throw new Error(deals.message); |
| 68 | const day = thisWeek(deals.value, on).filter(({ deadline }) => deadline.kind === "walkthrough" && deadline.due === addDays(on, 2)); | |
| 68 | const day = thisWeek(deals.value, on).filter(({ deal, deadline }) => deadline.kind === "walkthrough" && deadline.due === addDays(on, 2) && [a, b, c].some((x) => x.id === deal.id)); | |
| 69 | 69 | expect(day.map(({ deal }) => deal.address)).toEqual([c.address, b.address, a.address]); |
| 70 | 70 | expect(day.map(({ deadline }) => deadline.time)).toEqual(["09:00", "15:30", null]); |
| 71 | 71 | const html = render(); |
static/review.js added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | // Review keys: S sends, D opens the reason for Don't send, T holds until | |
| 2 | // tomorrow. Each presses the real button, so the same action and same-origin | |
| 3 | // check run. Only with focus on the card, never while typing in a field. | |
| 4 | const card = document.querySelector("[data-keys]"); | |
| 5 | card?.focus({ preventScroll: true }); | |
| 6 | card?.addEventListener("keydown", (e) => { | |
| 7 | if (e.metaKey || e.ctrlKey || e.altKey || e.repeat || e.target.closest("input,textarea,select,[contenteditable]")) return; | |
| 8 | const k = e.key.toLowerCase(); | |
outdated
e.key is interpolated into a CSS selector. A key like " or \ makes querySelector throw. Use a lookup that does not build a selector. |
||
| 9 | const b = [...card.querySelectorAll("button[data-key]")].find((x) => x.dataset.key === k); | |
| 10 | if (!b) return; | |
| 11 | e.preventDefault(); | |
| 12 | b.click(); | |
| 13 | }); |
new above
offline
Also assert data-key="t" on the Tomorrow button.