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

The sample deals tell a realtor which message to approve first when the app opens for a demo #240

Parked opened this
Closed without merging

mason/deal-clock:mason/235-the-sample-deals-tell-a-realtor-which-me → main 5 commits fork 3 threads · 3 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
6 files changed +59 −12
README.md +5 −4
@@ -46,10 +46,11 @@ looks like today.
4646 who made it. A "Date changed" notice is drafted for each party the date
4747 concerns. On 9 Orchard Row the appraisal has already been moved; open it to
4848 see where from and to, and why.
49 6. **Review and approve today's reminders.** Tap **Review** in the header. Each
50 unsent reminder shows the words it would send, already filled in, for a
51 party such as the buyer Samuel Reyes. Edit them if you like, then **Send**,
52 **Don't send** (it asks why) or **Tomorrow**. Send records your approval and
49 6. **Review and approve today's reminders.** Tap **Review** in the header. The
50 reminder whose date falls soonest (overdue first) comes first, marked
51 **Start here**. Each unsent reminder shows the words it would send, already
52 filled in, for a party such as the buyer Samuel Reyes. Edit them if you
outdated

Line is far past the wrapping used elsewhere; re-wrap.

53 like, then **Send**, **Don't send** (it asks why) or **Tomorrow**. Send records your approval and
5354 offers **Open in Mail** or **Open in Messages**, which open your own app with
5455 the words: deal-clock never sends anything itself. The count in the header
5556 goes down.
src/pages/review.ts +1 −1
@@ -102,7 +102,7 @@ function form(
102102 const invalid = (field: ReviewField): string => (error?.field === field ? ' aria-invalid="true"' : "");
103103 const skip = s.total - s.done > 1 ? reviewHref(s.q, s.at + 1, s.done) : "";
104104 return `<section class="card narrow">
105 <p class="eyebrow">${s.position} of ${s.total}</p>
105 <p class="eyebrow">${s.position} of ${s.total}${s.position === 1 && s.total > 1 ? ' <span class="badge" data-u="soon">Start here</span>' : ""}</p>
106106 <h1>Review today's reminders</h1>
107107 <p><a href="/deals/${draft.deal_id}">${escape(draft.address)}</a></p>
108108 <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>
src/reminders.ts +11
@@ -517,3 +517,14 @@ export const waitingCount = (deals: readonly DealView[], day: string, agent: Age
517517 (n, deal) => n + waitingIn(`${day}|${JSON.stringify(agent)}|${print(deal)}`, () => todaysDrafts([deal], day, agent).filter(unsent).length),
518518 0,
519519 );
520
521 /**
522 * The review page's order: the date that falls soonest first, overdue ahead of
523 * everything. A check-in or anniversary note hangs on a closing long past, so
524 * it ranks by the day it is sent, not the closing's date. Stable: ties keep
525 * the clock's order.
526 */
527 export const mostUrgentFirst = (queue: readonly Draft[]): Draft[] => {
528 const key = (d: Draft): string => (d.moment === "checkin" || d.moment === "anniversary" ? d.on : d.due);
529 return [...queue].sort((a, b) => (key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0));
530 };
outdated

The Map plus ! assertions are needless: sort on key(a) vs key(b) directly. Needs a direct unit test.

src/review.test.ts +14 −5
@@ -37,15 +37,13 @@ const post = (path: string, fields: Record<string, string>, headers: Record<stri
3737 };
3838 const keys = (s: ReturnType<typeof shown>) => ({ deadline: s.deadline, party: s.party, moment: s.moment, at: s.at, done: s.done, q: "" });
3939
40 test("the clock offers Review all, and the page's first draft is the clock's first row", async () => {
40 test("the clock offers Review all, and the page counts the clock's rows, starting at the most urgent", async () => {
4141 expect(await get("/")).toContain('href="/reminders/today">Review all</a>');
4242 const rows = await clockRows();
4343 const page = await get("/reminders/today");
4444 const first = shown(page);
45 const [deadline, name] = rows[0]!.split(":") as [string, string];
46 // A home anniversary note hangs on the deal's page, not on a date's sheet: the clock names no date for it.
47 if (deadline === "") expect(page).toContain(`<b>${name}</b>`);
48 else expect(first.deadline).toBe(deadline);
45 // The review page starts at the soonest date, which may not be the clock's first row, but it is one of them.
46 expect(rows.map((r) => r.split(":")[0])).toContain(first.deadline);
4947 expect(first.counter).toBe(`1/${rows.length}`);
5048 });
5149
@@ -212,3 +210,14 @@ test("Save contact takes an email and a phone together, and a bad phone keeps bo
212210 expect(after).toContain("[email protected]");
213211 expect(after).toContain("(555) 010-0199");
214212 });
213
214 test("the review page puts the soonest date first and marks it Start here, and only that one", async () => {
215 const page = await get("/reminders/today");
216 expect(page).toContain('<span class="badge" data-u="soon">Start here</span>');
217 expect(page.match(/Start here/g)?.length).toBe(1);
218 // The sample's overdue follow-up is the first draft, not merely somewhere on the page.
219 expect(shown(page).moment).toBe("late");
220 expect(page).toContain("Overdue follow-up");
221 const next = await get("/reminders/today?at=1");
222 expect(next).not.toContain("Start here");
outdated

This does not prove the order: overdue appears on the page regardless of position. Assert that the first draft is the overdue follow-up (its deadline/party) and add a unit test for mostUrgentFirst covering checkin/anniversary keying and stable ties.

223 });
src/routes.ts +2 −2
@@ -110,7 +110,7 @@ import { filePage } from "./pages/file.ts";
110110 import { timelinePage } from "./pages/timeline.ts";
111111 import { welcomePage } from "./pages/welcome.ts";
112112 import { failedCheck } from "./health.ts";
113 import { dueOn, remindsLine, todaysDrafts, unsent, waitingCount, type Agent, type Draft } from "./reminders.ts";
113 import { dueOn, mostUrgentFirst, remindsLine, todaysDrafts, unsent, waitingCount, type Agent, type Draft } from "./reminders.ts";
114114 import { token, tokensCss } from "./tokens.ts";
115115 import type { Who } from "./who.ts";
116116
@@ -602,7 +602,7 @@ const unconfirmed = (c: Context, path: string): Response =>
602602 function reviewQueue(c: Context, q: string): Result<Draft[]> {
603603 const deals = listDeals(c.db, c.who);
604604 if (!deals.ok) return deals;
605 return { ok: true, value: todaysDrafts(find(deals.value, q), dayOf(agentFor(c)), agentFor(c)).filter(unsent) };
605 return { ok: true, value: mostUrgentFirst(todaysDrafts(find(deals.value, q), dayOf(agentFor(c)), agentFor(c)).filter(unsent)) };
606606 }
607607
608608 /** Whose deals these are, read once per request however many times a page and its header ask. */
src/urgency.test.ts added +26
@@ -0,0 +1,26 @@
1 /** The review page's order: soonest date first, overdue ahead, notes by the day they go out. */
2 import { expect, test } from "bun:test";
3 import { mostUrgentFirst, type Draft } from "./reminders.ts";
4
5 const draft = (name: string, moment: Draft["moment"], due: string, on = due): Draft => ({ party_name: name, moment, due, on }) as Draft;
6 const names = (q: Draft[]): string[] => q.map((d) => d.party_name);
7
8 test("the earliest date comes first, so an overdue one leads", () => {
9 const q = [draft("later", "before", "2026-12-01"), draft("overdue", "late", "2026-10-01"), draft("soon", "day_of", "2026-11-12")];
10 expect(names(mostUrgentFirst(q))).toEqual(["overdue", "soon", "later"]);
11 });
12
13 test("a check-in or anniversary ranks by the day it goes out, not its closing's date", () => {
14 const q = [
15 draft("note", "checkin", "2024-03-01", "2026-11-20"),
16 draft("year", "anniversary", "2020-05-05", "2026-11-05"),
17 draft("date", "before", "2026-11-10"),
18 ];
19 expect(names(mostUrgentFirst(q))).toEqual(["year", "date", "note"]);
20 });
21
22 test("ties keep the clock's order, and the input is left alone", () => {
23 const q = [draft("a", "before", "2026-11-12"), draft("b", "day_of", "2026-11-12"), draft("c", "before", "2026-11-12")];
24 expect(names(mostUrgentFirst(q))).toEqual(["a", "b", "c"]);
25 expect(names(q)).toEqual(["a", "b", "c"]);
26 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs