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
mason/deal-clock:mason/235-the-sample-deals-tell-a-realtor-which-me → main 5 commits fork 3 threads · 3 unresolved
6 files
changed +59
−12
README.md +5 −4
| @@ -46,10 +46,11 @@ looks like today. | ||
| 46 | 46 | who made it. A "Date changed" notice is drafted for each party the date |
| 47 | 47 | concerns. On 9 Orchard Row the appraisal has already been moved; open it to |
| 48 | 48 | 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 | |
| 53 | like, then **Send**, **Don't send** (it asks why) or **Tomorrow**. Send records your approval and | |
| 53 | 54 | offers **Open in Mail** or **Open in Messages**, which open your own app with |
| 54 | 55 | the words: deal-clock never sends anything itself. The count in the header |
| 55 | 56 | goes down. |
src/pages/review.ts +1 −1
| @@ -102,7 +102,7 @@ function form( | ||
| 102 | 102 | const invalid = (field: ReviewField): string => (error?.field === field ? ' aria-invalid="true"' : ""); |
| 103 | 103 | const skip = s.total - s.done > 1 ? reviewHref(s.q, s.at + 1, s.done) : ""; |
| 104 | 104 | 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> | |
| 106 | 106 | <h1>Review today's reminders</h1> |
| 107 | 107 | <p><a href="/deals/${draft.deal_id}">${escape(draft.address)}</a></p> |
| 108 | 108 | <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 | ||
| 517 | 517 | (n, deal) => n + waitingIn(`${day}|${JSON.stringify(agent)}|${print(deal)}`, () => todaysDrafts([deal], day, agent).filter(unsent).length), |
| 518 | 518 | 0, |
| 519 | 519 | ); |
| 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 |
src/review.test.ts +14 −5
| @@ -37,15 +37,13 @@ const post = (path: string, fields: Record<string, string>, headers: Record<stri | ||
| 37 | 37 | }; |
| 38 | 38 | const keys = (s: ReturnType<typeof shown>) => ({ deadline: s.deadline, party: s.party, moment: s.moment, at: s.at, done: s.done, q: "" }); |
| 39 | 39 | |
| 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 () => { | |
| 41 | 41 | expect(await get("/")).toContain('href="/reminders/today">Review all</a>'); |
| 42 | 42 | const rows = await clockRows(); |
| 43 | 43 | const page = await get("/reminders/today"); |
| 44 | 44 | 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); | |
| 49 | 47 | expect(first.counter).toBe(`1/${rows.length}`); |
| 50 | 48 | }); |
| 51 | 49 | |
| @@ -212,3 +210,14 @@ test("Save contact takes an email and a phone together, and a bad phone keeps bo | ||
| 212 | 210 | expect(after).toContain("[email protected]"); |
| 213 | 211 | expect(after).toContain("(555) 010-0199"); |
| 214 | 212 | }); |
| 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: |
||
| 223 | }); |
src/routes.ts +2 −2
| @@ -110,7 +110,7 @@ import { filePage } from "./pages/file.ts"; | ||
| 110 | 110 | import { timelinePage } from "./pages/timeline.ts"; |
| 111 | 111 | import { welcomePage } from "./pages/welcome.ts"; |
| 112 | 112 | 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"; | |
| 114 | 114 | import { token, tokensCss } from "./tokens.ts"; |
| 115 | 115 | import type { Who } from "./who.ts"; |
| 116 | 116 | |
| @@ -602,7 +602,7 @@ const unconfirmed = (c: Context, path: string): Response => | ||
| 602 | 602 | function reviewQueue(c: Context, q: string): Result<Draft[]> { |
| 603 | 603 | const deals = listDeals(c.db, c.who); |
| 604 | 604 | 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)) }; | |
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | /** 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 | }); |
new above
offline
Line is far past the wrapping used elsewhere; re-wrap.