Public: anyone can read this; the crew can change it.
A deal whose closing is marked done leaves the clock for a Closed list, and can be reopened #28
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/20-a-deal-whose-closing-is-marked-done-leav → main 5 commits fork 1 thread · 1 unresolved
15 files
changed +171
−15
README.md +5 −1
| @@ -78,7 +78,11 @@ for the same list; over MCP, an agent asks for the `this_week` tool. | ||
| 78 | 78 | reason beside its field. In the terminal, press c instead of n for the same |
| 79 | 79 | list. Tap Open deal. You land on the new |
| 80 | 80 | deal's page with every date worked out, and it has its own lane on the clock. |
| 81 | 11. **Download the calendar file.** On a deal's page, tap Add to calendar. | |
| 81 | 11. **Close a deal.** Open a deal's page, tap Open on its Closing date and | |
| 82 | mark it done. The deal steps off the clock into the Closed card below it, | |
| 83 | its reminders stop, and its page says "Closed on …". Everything on it still | |
| 84 | opens; reopen the Closing date and the deal is back on the clock. | |
| 85 | 12. **Download the calendar file.** On a deal's page, tap Add to calendar. | |
| 82 | 86 | You get a calendar file with every date of the deal and an alarm three days |
| 83 | 87 | before and the morning of, to open in your own calendar app. |
| 84 | 88 |
contract/openapi.json +5
| @@ -952,6 +952,10 @@ | ||
| 952 | 952 | "type": "string", |
| 953 | 953 | "format": "date" |
| 954 | 954 | }, |
| 955 | "closed": { | |
| 956 | "type": "boolean", | |
| 957 | "description": "The Closing date is marked done; the deal is off the clock." | |
| 958 | }, | |
| 955 | 959 | "business_days": { |
| 956 | 960 | "enum": [ |
| 957 | 961 | 0, |
| @@ -1143,6 +1147,7 @@ | ||
| 1143 | 1147 | "address", |
| 1144 | 1148 | "contract_date", |
| 1145 | 1149 | "closing", |
| 1150 | "closed", | |
| 1146 | 1151 | "parties", |
| 1147 | 1152 | "deadlines" |
| 1148 | 1153 | ] |
docs/TECHNICAL.md +2
| @@ -36,6 +36,8 @@ sent until undone. Over the API: `POST /api/deals/:id/reminders/decline` and | ||
| 36 | 36 | `decline_reminder` and `undo_decline_reminder`; in the terminal, `n` then the |
| 37 | 37 | reason on the reminders list, and `u` to undo. Each is an update of the deal. |
| 38 | 38 | |
| 39 | A deal is **closed** when its Closing date is marked done (derived, no column; `closed` on `GET /api/deals` and `list_deals`). It leaves the clock for the Closed card, sends no reminders (`/tick`, `reminders_today`, the terminal `r` list), and the terminal date list shows its dates only after `h`. Reopening the Closing date reopens the deal. | |
| 40 | ||
| 39 | 41 | `POST /tick` answers the reminders that go out today and are not yet |
| 40 | 42 | marked sent, as JSON — call it each morning as a signed-in account (a |
| 41 | 43 | stranger gets 401; it sends nothing and changes nothing). `GET /deals/:id/ics` is a deal's calendar file. The JSON API is |
src/deadlines.ts +4
| @@ -36,6 +36,10 @@ export const KINDS = [ | ||
| 36 | 36 | ] as const; |
| 37 | 37 | export type Kind = (typeof KINDS)[number]; |
| 38 | 38 | |
| 39 | /** A deal is closed when its Closing date is marked done; reopening that date reopens the deal. */ | |
| 40 | export const isClosed = (deadlines: readonly { kind: Kind; done_at: string | null }[]): boolean => | |
| 41 | deadlines.some((d) => d.kind === "closing" && d.done_at !== null); | |
| 42 | ||
| 39 | 43 | export interface KindInfo { |
| 40 | 44 | readonly label: string; |
| 41 | 45 | /** Two or three letters for a marker on the clock. */ |
src/deals.test.ts +21
| @@ -25,6 +25,7 @@ import { | ||
| 25 | 25 | undoDecline, |
| 26 | 26 | type DealView, |
| 27 | 27 | } from "./deals.ts"; |
| 28 | import { isClosed } from "./deadlines.ts"; | |
| 28 | 29 | import { openDb } from "./db.ts"; |
| 29 | 30 | import { calendar, fold, icsText } from "./ics.ts"; |
| 30 | 31 | import { drafts, dueOn, recipients } from "./reminders.ts"; |
| @@ -417,3 +418,23 @@ test("a decline needs a reason of 1 to 200 characters, a real unsent reminder, a | ||
| 417 | 418 | sendReminder(db, alice, ask); |
| 418 | 419 | expect(declineReminder(db, alice, { ...ask, reason: "Too late" }).ok).toBe(false); |
| 419 | 420 | }); |
| 421 | ||
| 422 | test("a deal is closed when its Closing date is marked done, and open again when it is reopened", () => { | |
| 423 | const deal = open({ address: "31 Closed Ct" }); | |
| 424 | expect(deal.closed).toBe(false); | |
| 425 | expect(isClosed(deal.deadlines)).toBe(false); | |
| 426 | const beforeClosing = drafts(deal, agent).length; | |
| 427 | expect(beforeClosing).toBeGreaterThan(0); | |
| 428 | // Another date done does not close it. | |
| 429 | markDone(db, alice, { id: due(deal, "inspection").id, done: true }); | |
| 430 | expect(fresh(deal.id).closed).toBe(false); | |
| 431 | markDone(db, alice, { id: due(deal, "closing").id, done: true }); | |
| 432 | const closed = fresh(deal.id); | |
| 433 | expect(closed.closed).toBe(true); | |
| 434 | expect(drafts(closed, agent)).toEqual([]); | |
| 435 | expect(dueOn([closed], due(closed, "inspection").due, agent)).toEqual([]); | |
| 436 | markDone(db, alice, { id: due(deal, "closing").id, done: false }); | |
| 437 | expect(fresh(deal.id).closed).toBe(false); | |
| 438 | expect(isClosed([{ kind: "closing", done_at: "2026-11-02T10:00:00.000Z" }])).toBe(true); | |
| 439 | expect(isClosed([{ kind: "closing", done_at: null }, { kind: "custom", done_at: "x" }])).toBe(false); | |
| 440 | }); |
src/deals.ts +11 −1
| @@ -8,9 +8,10 @@ | ||
| 8 | 8 | |
| 9 | 9 | import type { Database } from "bun:sqlite"; |
| 10 | 10 | import { permit } from "./contract.ts"; |
| 11 | import { isDate } from "./dates.ts"; | |
| 11 | import { isDate, today } from "./dates.ts"; | |
| 12 | 12 | import { |
| 13 | 13 | DEFAULT_LENGTHS, |
| 14 | isClosed, | |
| 14 | 15 | isPartyRole, |
| 15 | 16 | KIND, |
| 16 | 17 | LENGTH_MAX, |
| @@ -95,10 +96,18 @@ export interface Deadline { | ||
| 95 | 96 | export interface DeadlineView extends Deadline { |
| 96 | 97 | readonly moves: readonly Move[]; |
| 97 | 98 | } |
| 99 | /** The day the Closing date was marked done, by the app's own calendar (the one `today()` keeps). */ | |
| 100 | export const closedOn = (deal: { deadlines: readonly { kind: Kind; done_at: string | null }[]; closing: string }): string => { | |
| 101 | const at = deal.deadlines.find((d) => d.kind === "closing")?.done_at; | |
| 102 | return at == null ? deal.closing : today(new Date(at)); | |
| 103 | }; | |
| 104 | ||
| 98 | 105 | /** A deal with everything hanging off it: what every page and door shows. */ |
| 99 | 106 | export interface DealView extends Deal { |
| 100 | 107 | /** The `closing` deadline's date, wherever it has moved. */ |
| 101 | 108 | readonly closing: string; |
| 109 | /** Its Closing date is marked done: the deal has stepped off the clock. */ | |
| 110 | readonly closed: boolean; | |
| 102 | 111 | readonly parties: readonly Party[]; |
| 103 | 112 | readonly deadlines: readonly DeadlineView[]; |
| 104 | 113 | readonly sent: readonly Sent[]; |
| @@ -167,6 +176,7 @@ function view(db: Database, deal: Deal): DealView { | ||
| 167 | 176 | ...deal, |
| 168 | 177 | closing: |
| 169 | 178 | deadlines.find((d) => d.kind === "closing")?.due ?? deal.contract_date, |
| 179 | closed: isClosed(deadlines), | |
| 170 | 180 | parties: db |
| 171 | 181 | .query<Party, [number]>( |
| 172 | 182 | "SELECT * FROM party WHERE deal_id = ?1 ORDER BY id", |
src/pages/clock.ts +17 −3
| @@ -116,7 +116,11 @@ export function clock(input: { | ||
| 116 | 116 | on: string; |
| 117 | 117 | notice?: string | undefined; |
| 118 | 118 | }): string { |
| 119 | const { who, deals, on, notice } = input; | |
| 119 | const { who, on, notice } = input; | |
| 120 | const deals = input.deals.filter((deal) => !deal.closed); | |
| 121 | const closed = input.deals | |
| 122 | .filter((deal) => deal.closed) | |
| 123 | .sort((a, b) => b.closing.localeCompare(a.closing) || b.id - a.id); | |
| 120 | 124 | const open = deals.flatMap((deal) => deal.deadlines.filter((d) => d.done_at === null)); |
| 121 | 125 | const overdue = open.filter((d) => urgency(d.due, on, false) === "overdue").length; |
| 122 | 126 | const soon = open.filter((d) => urgency(d.due, on, false) === "soon").length; |
| @@ -128,15 +132,24 @@ export function clock(input: { | ||
| 128 | 132 | ); |
| 129 | 133 | const toSend = today.filter(({ r }) => unsent(r)).length; |
| 130 | 134 | const timeline = |
| 131 | deals.length === 0 | |
| 135 | deals.length === 0 && closed.length === 0 | |
| 132 | 136 | ? `<p class="empty">No deals yet. <a href="/deals/new">Open the first one</a>.</p>` |
| 133 | : `<div class="clock-scroll" tabindex="0" role="region" aria-label="Timeline of every deal's dates"> | |
| 137 | : deals.length === 0 | |
| 138 | ? `<p class="empty">Every deal is closed.</p>` | |
| 139 | : `<div class="clock-scroll" tabindex="0" role="region" aria-label="Timeline of every deal's dates"> | |
| 134 | 140 | <div class="clock-inner" style="width:${at(days)}"> |
| 135 | 141 | <div class="axis" aria-hidden="true">${axis(start, days, on)}</div> |
| 136 | 142 | <ol class="lanes">${deals.map((deal) => lane(deal, start, on)).join("")}</ol> |
| 137 | 143 | </div> |
| 138 | 144 | </div> |
| 139 | 145 | ${deals.flatMap((deal) => deal.deadlines.map((d) => sheet(deal, d, who, on, "/"))).join("")}`; |
| 146 | const closedCard = | |
| 147 | closed.length === 0 | |
| 148 | ? "" | |
| 149 | : `<section id="closed" class="card" data-live="deal.changed"> | |
| 150 | <h2>Closed <span class="muted">· ${closed.length}</span></h2> | |
| 151 | <ul class="closed">${closed.map((deal) => `<li><a href="/deals/${deal.id}">${escape(deal.address)}</a> <span class="muted">closed ${escape(spoken(deal.closing))}</span></li>`).join("")}</ul> | |
| 152 | </section>`; | |
| 140 | 153 | const body = `<section class="intro"> |
| 141 | 154 | <div> |
| 142 | 155 | <h1>The clock</h1> |
| @@ -153,6 +166,7 @@ export function clock(input: { | ||
| 153 | 166 | <li><span class="dot" data-u="done"></span>Done</li> |
| 154 | 167 | </ul> |
| 155 | 168 | </section> |
| 169 | ${closedCard} | |
| 156 | 170 | ${deals.length === 0 ? "" : weekCard(deals, on)} |
| 157 | 171 | <section id="today" class="card" data-live="deal.changed"> |
| 158 | 172 | <h2>Reminders for today <span class="muted">· ${toSend === 0 ? "all sent" : `${toSend} to send`}</span></h2> |
src/pages/deal.ts +2 −2
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | import { addDays, relative, short, spoken } from "../dates.ts"; |
| 8 | import { canChange, canRemove, type DealView, type Party, type Plan, type PlannedDate, type Sent } from "../deals.ts"; | |
| 8 | import { canChange, canRemove, closedOn, type DealView, type Party, type Plan, type PlannedDate, type Sent } from "../deals.ts"; | |
| 9 | 9 | import { DEFAULT_LENGTHS, PARTY_LABEL, PARTY_ROLES } from "../deadlines.ts"; |
| 10 | 10 | import { escape } from "../http.ts"; |
| 11 | 11 | import { MOMENT_LABEL } from "../reminders.ts"; |
| @@ -108,7 +108,7 @@ export function dealPage(input: { | ||
| 108 | 108 | <section class="intro"> |
| 109 | 109 | <div> |
| 110 | 110 | <h1>${escape(deal.address)}</h1> |
| 111 | <p class="summary">Under contract ${escape(spoken(deal.contract_date))} · closes ${escape(spoken(deal.closing))}, ${escape(relative(deal.closing, on))}${deal.business_days ? " · business days" : ""}</p> | |
| 111 | <p class="summary">${deal.closed ? `<b>Closed on ${escape(spoken(closedOn(deal)))}</b> · ` : ""}Under contract ${escape(spoken(deal.contract_date))} · closes ${escape(spoken(deal.closing))}, ${escape(relative(deal.closing, on))}${deal.business_days ? " · business days" : ""}</p> | |
| 112 | 112 | </div> |
| 113 | 113 | <a class="button button-quiet" href="${path}/ics" download>Add to calendar</a> |
| 114 | 114 | </section> |
src/reminders.ts +2 −1
| @@ -72,8 +72,9 @@ function words( | ||
| 72 | 72 | }; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | /** Every reminder an open date of this deal has, sent or not. */ | |
| 75 | /** Every reminder an open date of this deal has, sent or not; a closed deal reminds no one. */ | |
| 76 | 76 | export function drafts(deal: DealView, agent: Agent): Draft[] { |
| 77 | if (deal.closed) return []; | |
| 77 | 78 | return deal.deadlines |
| 78 | 79 | .filter((d) => d.done_at === null) |
| 79 | 80 | .flatMap((deadline) => draftsFor(deal, deadline, agent)); |
src/routes.ts +2 −1
| @@ -125,6 +125,7 @@ export const DEAL: Schema = { | ||
| 125 | 125 | address: { type: "string" }, |
| 126 | 126 | contract_date: DATE, |
| 127 | 127 | closing: DATE, |
| 128 | closed: { type: "boolean", description: "The Closing date is marked done; the deal is off the clock." }, | |
| 128 | 129 | business_days: { enum: [0, 1] }, |
| 129 | 130 | author_id: { type: "string" }, |
| 130 | 131 | author_name: { type: "string" }, |
| @@ -188,7 +189,7 @@ export const DEAL: Schema = { | ||
| 188 | 189 | }, |
| 189 | 190 | }, |
| 190 | 191 | }, |
| 191 | required: ["id", "address", "contract_date", "closing", "parties", "deadlines"], | |
| 192 | required: ["id", "address", "contract_date", "closing", "closed", "parties", "deadlines"], | |
| 192 | 193 | }; |
| 193 | 194 | const NEW_DEAL: Schema = { |
| 194 | 195 | type: "object", |
src/server.test.ts +40
| @@ -2,6 +2,7 @@ import { afterAll, expect, test } from "bun:test"; | ||
| 2 | 2 | import { mkdtempSync } from "node:fs"; |
| 3 | 3 | import { tmpdir } from "node:os"; |
| 4 | 4 | import { join } from "node:path"; |
| 5 | import { addDays, spoken, today } from "./dates.ts"; | |
| 5 | 6 | import { agent, env } from "./env.ts"; |
| 6 | 7 | import { drafts } from "./reminders.ts"; |
| 7 | 8 | import { serve } from "./server.ts"; |
| @@ -792,6 +793,45 @@ test("Check the dates refuses a guest and writes nothing; a refusal with no fiel | ||
| 792 | 793 | expect(page).not.toContain("-why"); |
| 793 | 794 | }); |
| 794 | 795 | |
| 796 | // Its own person: writes are rationed per person across the whole run. | |
| 797 | const closer = as("u20", "closer"); | |
| 798 | test("a deal whose Closing is marked done leaves the lanes for the Closed card, and sends nothing", async () => { | |
| 799 | // The inspection ends in three days, so a reminder for this deal goes out today. | |
| 800 | const made = await api( | |
| 801 | "/api/deals", | |
| 802 | { method: "POST", ...jsonBody({ address: "77 Closing Court", buyer: "B", seller: "S", contract_date: addDays(today(), -7), closing_date: addDays(today(), 25) }) }, | |
| 803 | closer, | |
| 804 | ); | |
| 805 | expect(made.status).toBe(201); | |
| 806 | const deal = (await made.json()) as { id: number; address: string; closed: boolean; deadlines: { id: number; kind: string }[] }; | |
| 807 | expect(deal.closed).toBe(false); | |
| 808 | const tickIds = async () => | |
| 809 | ((await (await api("/tick", { method: "POST" }, closer)).json()) as { reminders: { deal_id: number }[] }).reminders.map((r) => r.deal_id); | |
| 810 | expect(await tickIds()).toContain(deal.id); | |
| 811 | const closing = deal.deadlines.find((d) => d.kind === "closing")!; | |
| 812 | const post = (done: string) => { | |
| 813 | const body = new FormData(); | |
| 814 | body.set("done", done); | |
| 815 | return api(`/deadlines/${closing.id}/done`, { method: "POST", body, redirect: "manual" }, closer); | |
| 816 | }; | |
| 817 | expect((await api("/", {}, closer).then((r) => r.text()))).toContain(`<a href="/deals/${deal.id}">${deal.address}</a> <small`); | |
| 818 | expect((await post("1")).status).toBe(303); | |
| 819 | const clock = await (await api("/", {}, closer)).text(); | |
| 820 | expect(clock).not.toContain(`<a href="/deals/${deal.id}">${deal.address}</a> <small`); | |
| 821 | expect(clock).toContain('id="closed"'); | |
| 822 | expect(clock).toContain(`<a href="/deals/${deal.id}">${deal.address}</a> <span class="muted">closed`); | |
| 823 | const page = await (await api(`/deals/${deal.id}`, {}, closer)).text(); | |
| 824 | expect(page).toContain(`Closed on ${spoken(today())}`); | |
| 825 | expect(page).toContain("Inspection period ends"); | |
| 826 | const listed = (await (await api("/api/deals", {}, closer)).json()) as { id: number; closed: boolean }[]; | |
| 827 | expect(listed.find((d) => d.id === deal.id)!.closed).toBe(true); | |
| 828 | expect(await tickIds()).not.toContain(deal.id); | |
| 829 | expect((await post("0")).status).toBe(303); | |
| 830 | const back = await (await api("/", {}, closer)).text(); | |
| 831 | expect(back).toContain(`<a href="/deals/${deal.id}">${deal.address}</a> <small`); | |
| 832 | expect(back).not.toContain('id="closed"'); | |
| 833 | }); | |
| 834 | ||
| 795 | 835 | test("This week lists the sample's overdue inspection and this week's closing, and nothing done", async () => { |
| 796 | 836 | const page = await (await api("/", {}, alice)).text(); |
| 797 | 837 | const week = page.slice(page.indexOf('id="week"'), page.indexOf('id="today"')); |
src/terminal.test.ts +38 −2
| @@ -6,8 +6,8 @@ import { expect, test } from "bun:test"; | ||
| 6 | 6 | import { mkdtempSync } from "node:fs"; |
| 7 | 7 | import { tmpdir } from "node:os"; |
| 8 | 8 | import { join } from "node:path"; |
| 9 | import { addDays, today } from "./dates.ts"; | |
| 10 | import { addDeadline, addParty, createDeal, getDeal, listDeals, sendReminder, type DealView } from "./deals.ts"; | |
| 9 | import { addDays, spoken, today } from "./dates.ts"; | |
| 10 | import { addDeadline, addParty, createDeal, getDeal, listDeals, markDone, sendReminder, type DealView } from "./deals.ts"; | |
| 11 | 11 | import { openDb } from "./db.ts"; |
| 12 | 12 | import { terminal, type Terminal } from "./terminal.ts"; |
| 13 | 13 | import type { Who } from "./who.ts"; |
| @@ -265,6 +265,42 @@ test("n declines a reminder with a reason, u undoes it; anon is not asked to typ | ||
| 265 | 265 | expect(db.query<{ n: number }, []>("SELECT count(*) AS n FROM reminder_declined").get()!.n).toBe(before); |
| 266 | 266 | }); |
| 267 | 267 | |
| 268 | test("a closed deal's dates leave the date list and reminders, it is listed under Closed, and u reopens it", () => { | |
| 269 | // The inspection ends in three days, so its "3 days before" reminder goes out today. | |
| 270 | const other = createDeal(db, alice, { | |
| 271 | address: "88 Shut Ave", | |
| 272 | buyer: "B", | |
| 273 | seller: "S", | |
| 274 | contractDate: addDays(today(), -7), | |
| 275 | closingDate: addDays(today(), 20), | |
| 276 | }); | |
| 277 | if (!other.ok) throw new Error(other.message); | |
| 278 | const closing = other.value.deadlines.find((d) => d.kind === "closing")!; | |
| 279 | const t = terminal(db, alice, context); | |
| 280 | t.press("r"); | |
| 281 | expect(lines(t).join("\n")).toContain("88 Shut Ave"); | |
| 282 | t.press("d"); | |
| 283 | expect(lines(t).join("\n")).toContain("88 Shut Ave"); | |
| 284 | expect(lines(t).join("\n")).not.toContain("Closed ("); | |
| 285 | markDone(db, alice, { id: closing.id, done: true }); | |
| 286 | t.press("d"); | |
| 287 | const dates = lines(t).join("\n"); | |
| 288 | expect(dates).not.toContain("Inspection period ends — 88 Shut Ave"); | |
| 289 | expect(dates).toContain("Closed (1)"); | |
| 290 | expect(dates).toContain(`88 Shut Ave — closed ${spoken(today())}`); | |
| 291 | t.press("r"); | |
| 292 | expect(lines(t).join("\n")).not.toContain("88 Shut Ave"); | |
| 293 | t.press("d"); | |
| 294 | t.press("h"); | |
| 295 | expect(lines(t).join("\n")).toContain("Inspection period ends — 88 Shut Ave"); | |
| 296 | expect(lines(t).join("\n")).toContain("(closed)"); | |
| 297 | goTo(t, "Closing — 88 Shut Ave"); | |
| 298 | t.press("u"); | |
| 299 | t.press("h"); | |
| 300 | expect(lines(t).join("\n")).not.toContain("Closed ("); | |
| 301 | expect(lines(t).join("\n")).toContain("Inspection period ends — 88 Shut Ave"); | |
| 302 | }); | |
| 303 | ||
| 268 | 304 | test("w lists the dates overdue or due within seven days, by day, with who owes each; x works there", () => { |
| 269 | 305 | const soon = addDeadline(db, alice, { dealId: id, label: "Week check", due: addDays(today(), 2), owes: "buyer" }); |
| 270 | 306 | if (!soon.ok) throw new Error(soon.message); |
src/terminal.ts +13 −3
| @@ -25,6 +25,7 @@ import { | ||
| 25 | 25 | createDeal, |
| 26 | 26 | deleteDeal, |
| 27 | 27 | getDeal, |
| 28 | closedOn, | |
| 28 | 29 | listDeals, |
| 29 | 30 | markDone, |
| 30 | 31 | mayOpen, |
| @@ -109,7 +110,7 @@ export function terminal( | ||
| 109 | 110 | if (view === "week") return thisWeek(deals(), on()).map(({ deal, deadline }) => ({ deal, date: deadline })); |
| 110 | 111 | return deals() |
| 111 | 112 | .flatMap((deal) => |
| 112 | deal.deadlines.filter((d) => showDone || d.done_at === null).map((date) => ({ deal, date })), | |
| 113 | (deal.closed && !showDone ? [] : deal.deadlines.filter((d) => showDone || d.done_at === null)).map((date) => ({ deal, date })), | |
| 113 | 114 | ) |
| 114 | 115 | .sort((a, b) => a.date.due.localeCompare(b.date.due) || a.date.id - b.date.id); |
| 115 | 116 | }; |
| @@ -388,7 +389,8 @@ export function terminal( | ||
| 388 | 389 | const u = urgency(date.due, on(), date.done_at !== null); |
| 389 | 390 | const when = tint(u, `${spoken(date.due).padEnd(12)} ${(date.done_at === null ? relative(date.due, on()) : "done").padEnd(12)}`); |
| 390 | 391 | const who = owner(deal, date); |
| 391 | const text = view === "week" ? `${date.label} — ${deal.address} · ${who.name ?? who.role}` : withDeal ? `${date.label} — ${deal.address}` : date.label; | |
| 392 | const label = view === "week" ? `${date.label} — ${deal.address} · ${who.name ?? who.role}` : withDeal ? `${date.label} — ${deal.address}` : date.label; | |
| 393 | const text = label + (deal.closed && withDeal ? dim(" (closed)") : ""); | |
| 392 | 394 | const moved = date.moves.length > 0 ? dim(` moved: ${date.moves.at(-1)!.reason}`) : ""; |
| 393 | 395 | return `${i === cursor ? "▸" : " "} ${when} ${i === cursor ? bold(text) : text}${moved}`; |
| 394 | 396 | }; |
| @@ -408,6 +410,14 @@ export function terminal( | ||
| 408 | 410 | if (!listed.ok) lines.push(listed.message); |
| 409 | 411 | else if (rows.length === 0) lines.push(dim("Nothing open. Every date is done.")); |
| 410 | 412 | rows.forEach((row, i) => lines.push(dateLine(row, i, true))); |
| 413 | const closed = all.filter((d) => d.closed); | |
| 414 | if (closed.length > 0) | |
| 415 | lines.push( | |
| 416 | "", | |
| 417 | bold(`Closed (${closed.length})`), | |
| 418 | ...closed.map((d) => dim(` ${d.address} — closed ${spoken(closedOn(d))}`)), | |
| 419 | dim(showDone ? " Their dates are listed above; u on the Closing date reopens the deal." : " h shows their dates; u on the Closing date reopens the deal."), | |
| 420 | ); | |
| 411 | 421 | } else if (view === "week") { |
| 412 | 422 | const rows = dateRows(); |
| 413 | 423 | const listed = listDeals(db, me); |
| @@ -437,7 +447,7 @@ export function terminal( | ||
| 437 | 447 | const deal = openDeal(); |
| 438 | 448 | if (deal === undefined) lines.push(dim("That deal is gone.")); |
| 439 | 449 | else { |
| 440 | lines.push(bold(deal.address), dim(`under contract ${spoken(deal.contract_date)} · closes ${spoken(deal.closing)}, ${relative(deal.closing, day)}`), ""); | |
| 450 | lines.push(bold(deal.address), ...(deal.closed ? [bold(`Closed on ${spoken(closedOn(deal))}`)] : []), dim(`under contract ${spoken(deal.contract_date)} · closes ${spoken(deal.closing)}, ${relative(deal.closing, day)}`), ""); | |
| 441 | 451 | deal.deadlines.forEach((date, i) => lines.push(dateLine({ deal, date }, i, false))); |
| 442 | 452 | lines.push("", bold("Parties")); |
| 443 | 453 | deal.parties.forEach((p, i) => { |
src/week.test.ts +5
| @@ -31,3 +31,8 @@ test("overdue first, then by due date, then by address", () => { | ||
| 31 | 31 | test("nothing in the window is an empty list", () => { |
| 32 | 32 | expect(thisWeek([], on)).toEqual([]); |
| 33 | 33 | }); |
| 34 | ||
| 35 | test("a closed deal's dates are left out", () => { | |
| 36 | const shut = { address: "C Street", closed: true, deadlines: [d("2026-11-03")] }; | |
| 37 | expect(thisWeek([...deals, shut], on).some((i) => i.deal.address === "C Street")).toBe(false); | |
| 38 | }); |
src/week.ts +4 −1
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /** |
| 2 | * The dates to chase this week: every open date that is overdue or falls | |
| 2 | * The dates to chase this week: every open date of an open deal that is overdue or falls | |
| 3 | 3 | * within the next seven days, oldest first, then by address. |
| 4 | 4 | */ |
| 5 | 5 | |
| @@ -11,6 +11,8 @@ export const WEEK = 7; | ||
| 11 | 11 | |
| 12 | 12 | export interface WeekDeal<D> { |
| 13 | 13 | readonly address: string; |
| 14 | /** A closed deal is off the clock, so none of its dates are chased. */ | |
| 15 | readonly closed?: boolean; | |
| 14 | 16 | readonly deadlines: readonly D[]; |
| 15 | 17 | } |
| 16 | 18 | |
| @@ -25,6 +27,7 @@ export function thisWeek<D extends { due: string; done_at: string | null }, Deal | ||
| 25 | 27 | ): WeekItem<Deal, D>[] { |
| 26 | 28 | const last = addDays(on, WEEK); |
| 27 | 29 | return deals |
| 30 | .filter((deal) => deal.closed !== true) | |
| 28 | 31 | .flatMap((deal) => |
| 29 | 32 | deal.deadlines.filter((d) => d.done_at === null && d.due <= last).map((deadline) => ({ deal, deadline })), |
| 30 | 33 | ) |
new above
offline
Vacuous unless a reminder for this deal is due today. Make one due, assert it appears in r before markDone, and is absent after.