Public: anyone can read this; the crew can change it.

small: The review page's finished screen also says how many reminders were held until tomorrow #257

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/deal-clock:mason/255-small-the-review-page-s-finished-screen → main 1 commit fork

  • Merged. mason/255-small-the-review-page-s-finished-screen was merged into main as 81d12a2.

Review

Sign in to review this change.
3 files changed +24 −7
src/review.test.ts +10
@@ -239,3 +239,13 @@ test("the finished screen says how many were approved and declined today, counte
239239 // The count does not come from the query string.
240240 expect(await get("/reminders/today?q=zzzz-no-such-deal&done=9")).toContain(line![0]);
241241 });
242
243 test("the finished screen adds how many were held until tomorrow, and nothing when none were", async () => {
244 const count = (page: string) => Number(/(\d+) held until tomorrow\./.exec(page)?.[1] ?? 0);
245 const before = count(await get("/reminders/today?q=zzzz-no-such-deal"));
246 const one = shown(await get("/reminders/today"));
247 expect((await post("/reminders/today/hold", { ...keys(one), subject: "s", body: "b" })).status).toBeLessThan(400);
248 const after = await get("/reminders/today?q=zzzz-no-such-deal");
249 expect(count(after)).toBe(before + 1);
250 expect(await get("/reminders/today?q=zzzz-no-such-deal&done=9")).toContain(`${before + 1} held until tomorrow.`);
251 });
src/settled.test.ts +6 −4
@@ -2,8 +2,10 @@ import { expect, test } from "bun:test";
22 import { settledLine } from "./settled.ts";
33
44 test("the line names what was approved and declined, and is empty when nothing was", () => {
5 expect(settledLine({ sent: 3, declined: 1 })).toBe("You approved 3 and declined 1 today.");
6 expect(settledLine({ sent: 2, declined: 0 })).toBe("You approved 2 today.");
7 expect(settledLine({ sent: 0, declined: 4 })).toBe("You declined 4 today.");
8 expect(settledLine({ sent: 0, declined: 0 })).toBe("");
5 expect(settledLine({ sent: 3, declined: 1, held: 0 })).toBe("You approved 3 and declined 1 today.");
6 expect(settledLine({ sent: 2, declined: 0, held: 0 })).toBe("You approved 2 today.");
7 expect(settledLine({ sent: 0, declined: 4, held: 0 })).toBe("You declined 4 today.");
8 expect(settledLine({ sent: 0, declined: 0, held: 0 })).toBe("");
9 expect(settledLine({ sent: 3, declined: 1, held: 2 })).toBe("You approved 3 and declined 1 today. 2 held until tomorrow.");
10 expect(settledLine({ sent: 0, declined: 0, held: 1 })).toBe("1 held until tomorrow.");
911 });
src/settled.ts +8 −3
@@ -10,6 +10,8 @@ import { dayOfStamp } from "./dates.ts";
1010 export interface Settled {
1111 readonly sent: number;
1212 readonly declined: number;
13 /** Held today and still held: a release deletes the hold. */
14 readonly held: number;
1315 }
1416
1517 /** Records written in the last two days, read in one query, then kept if they fall on `day` in `zone`. */
@@ -28,11 +30,14 @@ export function settledOn(db: Database, zone: string, day: string): Settled {
2830 if (r.kind === "s") sent++;
2931 else declined++;
3032 }
31 return { sent, declined };
33 const held = db.query<{ n: number }, [string]>("SELECT count(*) AS n FROM reminder_hold WHERE held_on = ?1").get(day)!.n;
34 return { sent, declined, held };
3235 }
3336
34 /** "You approved 3 and declined 1 today."; empty when nothing was settled today. */
37 /** "You approved 3 and declined 1 today. 2 held until tomorrow."; empty when nothing was settled or held today. */
3538 export function settledLine(s: Settled): string {
3639 const parts = [s.sent > 0 ? `approved ${s.sent}` : "", s.declined > 0 ? `declined ${s.declined}` : ""].filter((p) => p !== "");
37 return parts.length === 0 ? "" : `You ${parts.join(" and ")} today.`;
40 const done = parts.length === 0 ? "" : `You ${parts.join(" and ")} today.`;
41 const held = s.held > 0 ? `${s.held} held until tomorrow.` : "";
42 return [done, held].filter((p) => p !== "").join(" ");
3843 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs