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

Merged opened this

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

Merged

mason/deal-clock:mason/79-the-client-timeline-prints-as-a-clean-on → main 1 commit fork

  • Merged. mason/79-the-client-timeline-prints-as-a-clean-on was merged into main as 5860a20.

Review

Sign in to review this change.
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
131131 Add all to calendar does the same for every open date of every open deal.
132132 13. **Print the client timeline.** On a sample deal's page, tap Client
133133 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
136136 t; over MCP, an agent asks for the `client_timeline` tool.
137137 14. **Fix an address.** On a deal's page, Edit address corrects a typo in
138138 place: the clock, the client timeline, the calendar file and unsent drafts
docs/design/areas/timeline.md +2 −1
@@ -3,7 +3,8 @@
33 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.
44
55 - `.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.
78 - `body.timeline-page` — scopes every print rule to this page.
89 - `.timeline-list` — the ordered list of dates, no markers.
910 - `.timeline-row` — one date; never split across printed pages.
src/pages/timeline.ts +6 −4
@@ -2,13 +2,14 @@
22 * A deal's client timeline at `/deals/:id/timeline`: the page the agent
33 * shows or prints for a buyer or seller. Its dates in due order, who owes
44 * 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.
67 */
78
89 import type { DealView } from "../deals.ts";
910 import type { Agent } from "../reminders.ts";
1011 import { agent as defaults } from "../env.ts";
11 import { escape } from "../http.ts";
12 import { asset, escape } from "../http.ts";
1213 import { timelineRows } from "../timeline.ts";
1314 import type { Who } from "../who.ts";
1415 import { contactLinks } from "./contact.ts";
@@ -28,12 +29,13 @@ export function timelinePage(input: { who: Who; agent?: Agent | undefined; deal:
2829 </li>`,
2930 )
3031 .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>
3233 <section class="timeline">
3334 <h1>${escape(deal.address)}</h1>
3435 <p class="summary">Key dates, prepared by ${escape(agent.name)}, ${escape(agent.brokerage)}</p>
3536 <p class="summary">${contactLinks(agent)}</p>
3637 <ol class="timeline-list">${rows}</ol>
37 </section>`;
38 </section>
39 <script src="${asset("print.js")}"></script>`;
3840 return layout({ body, who, agent, path, heading: `Timeline · ${deal.address}`, plain: true, bodyClass: "timeline-page" });
3941 }
src/timeline.test.ts +26 −2
@@ -46,8 +46,6 @@ test("lists the dates in due order with owners and status words", () => {
4646 test("has no forms, scripts, contacts or removed dates, and escapes the address", () => {
4747 const html = page("2026-10-25");
4848 expect(html).not.toContain("<form");
49 expect(html).not.toContain("<script");
50 expect(html).not.toContain("<button");
5149 expect(html).not.toContain("[email protected]");
5250 expect(html).not.toContain("[email protected]");
5351 expect(html).not.toContain("Gone repair date");
@@ -78,3 +76,29 @@ test("the terminal shows the same dates and owners for the open deal, ", () => {
7876 t.press("b");
7977 expect(t.screen().join("\n")).not.toContain("Client timeline");
8078 });
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 {
913913 line-height: 1;
914914 }
915915
916 /* The Print button shows only once print.js has revealed it. */
917 .timeline-tools [data-print][hidden] {
918 display: none;
919 }
920
916921 /* On paper: only the client timeline changes — black on white, no tools, no row split. */
917922 @media print {
918923 .timeline-page {
@@ -921,7 +926,8 @@ a.marker {
921926 }
922927 .timeline-page .head,
923928 .timeline-page footer,
924 .timeline-page .timeline-tools {
929 .timeline-page .timeline-tools,
930 .timeline-page .toast {
925931 display: none;
926932 }
927933 .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 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs