Public: anyone can read this; the crew can change it.
The client timeline prints as a clean one-page handout the agent can hand a buyer across the table #83
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/79-the-client-timeline-prints-as-a-clean-on → main 1 commit fork
6 files
changed +51
−10
README.md +2 −2
| @@ -131,8 +131,8 @@ Signed out, `/` shows what deal-clock does, three short points, a still picture | ||
| 131 | 131 | Add all to calendar does the same for every open date of every open deal. |
| 132 | 132 | 13. **Print the client timeline.** On a sample deal's page, tap Client |
| 133 | 133 | timeline: its dates in order, who owes each and whether it is done, |
| 134 | upcoming or overdue, with no controls. Print it with your browser's print | |
| 135 | to hand to a buyer or seller. In the terminal, open the deal with o and press | |
| 134 | upcoming or overdue, with no controls. Tap Print to make the one-page handout | |
| 135 | for a buyer or seller (the browser's own print works too). In the terminal, open the deal with o and press | |
| 136 | 136 | t; over MCP, an agent asks for the `client_timeline` tool. |
| 137 | 137 | 14. **Fix an address.** On a deal's page, Edit address corrects a typo in |
| 138 | 138 | place: the clock, the client timeline, the calendar file and unsent drafts |
docs/design/areas/timeline.md +2 −1
| @@ -3,7 +3,8 @@ | ||
| 3 | 3 | Classes on `/deals/:id/timeline`, the page handed to a client. It prints portrait Letter/A4, black on white, with no header, footer or tools. |
| 4 | 4 | |
| 5 | 5 | - `.timeline` — the page's one section. |
| 6 | - `.timeline-tools` — the hint to print and the link back; on screen only. | |
| 6 | - `.timeline-tools` — the Print button, the hint to print and the link back; on screen only. | |
| 7 | - `[data-print]` — the Print button (existing `.button`, `.button-small`); `hidden` until `static/print.js` runs, so it is absent without JavaScript. | |
| 7 | 8 | - `body.timeline-page` — scopes every print rule to this page. |
| 8 | 9 | - `.timeline-list` — the ordered list of dates, no markers. |
| 9 | 10 | - `.timeline-row` — one date; never split across printed pages. |
src/pages/timeline.ts +6 −4
| @@ -2,13 +2,14 @@ | ||
| 2 | 2 | * A deal's client timeline at `/deals/:id/timeline`: the page the agent |
| 3 | 3 | * shows or prints for a buyer or seller. Its dates in due order, who owes |
| 4 | 4 | * each and whether it is done, upcoming or overdue — and nothing internal: |
| 5 | * no forms, drafts, reasons, audit or contacts. No script is sent. | |
| 5 | * no forms, drafts, reasons, audit or contacts. Its one script, `static/print.js`, | |
| 6 | * only shows the Print button. | |
| 6 | 7 | */ |
| 7 | 8 | |
| 8 | 9 | import type { DealView } from "../deals.ts"; |
| 9 | 10 | import type { Agent } from "../reminders.ts"; |
| 10 | 11 | import { agent as defaults } from "../env.ts"; |
| 11 | import { escape } from "../http.ts"; | |
| 12 | import { asset, escape } from "../http.ts"; | |
| 12 | 13 | import { timelineRows } from "../timeline.ts"; |
| 13 | 14 | import type { Who } from "../who.ts"; |
| 14 | 15 | import { contactLinks } from "./contact.ts"; |
| @@ -28,12 +29,13 @@ export function timelinePage(input: { who: Who; agent?: Agent | undefined; deal: | ||
| 28 | 29 | </li>`, |
| 29 | 30 | ) |
| 30 | 31 | .join(""); |
| 31 | const body = `<p class="crumb timeline-tools"><a href="/deals/${deal.id}">← Back to the deal</a> · To print, use your browser's print (Ctrl/Cmd+P)</p> | |
| 32 | const body = `<p class="crumb timeline-tools"><a href="/deals/${deal.id}">← Back to the deal</a> · <button type="button" class="button button-small" data-print hidden>Print</button> <span class="muted">or your browser's print (Ctrl/Cmd+P)</span></p> | |
| 32 | 33 | <section class="timeline"> |
| 33 | 34 | <h1>${escape(deal.address)}</h1> |
| 34 | 35 | <p class="summary">Key dates, prepared by ${escape(agent.name)}, ${escape(agent.brokerage)}</p> |
| 35 | 36 | <p class="summary">${contactLinks(agent)}</p> |
| 36 | 37 | <ol class="timeline-list">${rows}</ol> |
| 37 | </section>`; | |
| 38 | </section> | |
| 39 | <script src="${asset("print.js")}"></script>`; | |
| 38 | 40 | return layout({ body, who, agent, path, heading: `Timeline · ${deal.address}`, plain: true, bodyClass: "timeline-page" }); |
| 39 | 41 | } |
src/timeline.test.ts +26 −2
| @@ -46,8 +46,6 @@ test("lists the dates in due order with owners and status words", () => { | ||
| 46 | 46 | test("has no forms, scripts, contacts or removed dates, and escapes the address", () => { |
| 47 | 47 | const html = page("2026-10-25"); |
| 48 | 48 | expect(html).not.toContain("<form"); |
| 49 | expect(html).not.toContain("<script"); | |
| 50 | expect(html).not.toContain("<button"); | |
| 51 | 49 | expect(html).not.toContain("[email protected]"); |
| 52 | 50 | expect(html).not.toContain("[email protected]"); |
| 53 | 51 | expect(html).not.toContain("Gone repair date"); |
| @@ -78,3 +76,29 @@ test("the terminal shows the same dates and owners for the open deal, ", () => { | ||
| 78 | 76 | t.press("b"); |
| 79 | 77 | expect(t.screen().join("\n")).not.toContain("Client timeline"); |
| 80 | 78 | }); |
| 79 | ||
| 80 | test("offers Print from a static script, with no inline script or handler", async () => { | |
| 81 | const html = page("2026-10-25"); | |
| 82 | expect(html).toContain("data-print hidden>Print</button>"); | |
| 83 | const src = html.match(/<script src="([^"]+)"><\/script>/)?.[1]; | |
| 84 | expect(src).toMatch(/^\/static\/print\.js\?v=[0-9a-f]{8}$/); | |
| 85 | expect([...html.matchAll(/<script\b[^>]*>/g)].every((m) => m[0].includes(" src="))).toBe(true); | |
| 86 | expect(html).not.toMatch(/<script[^>]*>\s*[^<\s]/); | |
| 87 | expect(html).not.toMatch(/\son[a-z]+\s*=/i); | |
| 88 | const js = await Bun.file(join(import.meta.dir, "..", "static", "print.js")).text(); | |
| 89 | expect(js).toContain("window.print()"); | |
| 90 | const css = await Bun.file(join(import.meta.dir, "..", "static", "app.css")).text(); | |
| 91 | const print = css.slice(css.indexOf("@media print")); | |
| 92 | expect(print).toContain("break-inside: avoid"); | |
| 93 | expect(print).toContain(".timeline-tools"); | |
| 94 | expect(print).toContain(".toast"); | |
| 95 | expect(print).toContain(".head"); | |
| 96 | }); | |
| 97 | ||
| 98 | test("prints the agent's name, brokerage, phone and email once, and each status as text and mark", () => { | |
| 99 | const html = timelinePage({ who: alice, deal: (getDeal(db, alice, { id }) as { ok: true; value: never }).value, on: "2026-10-25", agent: { name: "Dana Whitfield", brokerage: "Hearth Realty", phone: "555-0100", email: "[email protected]" } }); | |
| 100 | expect(html.split("Hearth Realty").length - 1).toBeGreaterThanOrEqual(1); | |
| 101 | expect(html).toContain("555-0100"); | |
| 102 | expect(html).toContain("[email protected]"); | |
| 103 | expect(html).toMatch(/timeline-status"><span aria-hidden="true">\S+<\/span> (Done|Upcoming|Overdue)/); | |
| 104 | }); |
static/app.css +7 −1
| @@ -913,6 +913,11 @@ a.marker { | ||
| 913 | 913 | line-height: 1; |
| 914 | 914 | } |
| 915 | 915 | |
| 916 | /* The Print button shows only once print.js has revealed it. */ | |
| 917 | .timeline-tools [data-print][hidden] { | |
| 918 | display: none; | |
| 919 | } | |
| 920 | ||
| 916 | 921 | /* On paper: only the client timeline changes — black on white, no tools, no row split. */ |
| 917 | 922 | @media print { |
| 918 | 923 | .timeline-page { |
| @@ -921,7 +926,8 @@ a.marker { | ||
| 921 | 926 | } |
| 922 | 927 | .timeline-page .head, |
| 923 | 928 | .timeline-page footer, |
| 924 | .timeline-page .timeline-tools { | |
| 929 | .timeline-page .timeline-tools, | |
| 930 | .timeline-page .toast { | |
| 925 | 931 | display: none; |
| 926 | 932 | } |
| 927 | 933 | .timeline-page .page { |
static/print.js added +8
| @@ -0,0 +1,8 @@ | ||
| 1 | // The Print button on the client timeline. It is hidden until this file | |
| 2 | // runs, so without JavaScript the page offers no dead button and still | |
| 3 | // prints from the browser's menu. | |
| 4 | ||
| 5 | for (const button of document.querySelectorAll("[data-print]")) { | |
| 6 | button.hidden = false; | |
| 7 | button.addEventListener("click", () => window.print()); | |
| 8 | } |
new above
offline