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

Each deal shows a Messages record: every reminder sent for it, newest first, with who, when and the exact words approved #26

Merged opened this

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

Merged

mason/deal-clock:mason/23-each-deal-shows-a-messages-record-every → main 2 commits fork

  • Merged. mason/23-each-deal-shows-a-messages-record-every was merged into main as 2f6d6ec.

Review

Sign in to review this change.
13 files changed +200 −17
README.md +4
@@ -38,6 +38,10 @@ since they were last set, so the screen always looks like today.
3838 Decided against a message? Beside Send, **Don't send** asks why (up to 200
3939 characters). The reminder stops counting as "to send" and reads "Not sent:
4040 <reason> · <who>"; the reason is kept, and **Undo** makes it a draft again.
41 Every message you sent is kept: open 1418 Alder Lane's page and find
42 **Messages**, newest first, each with who it went to, which date and
43 moment, the day it was sent, and (tap it open) the exact words you approved.
44 In the terminal: open the deal with o, then press s.
4145 5. **Move a date, with a reason.** Open the same marker again and use Move
4246 this date: pick a new date and say why ("Inspector delayed"). The marker
4347 jumps to the new date, and the sheet lists the move, the reason and who
contract/openapi.json +12
@@ -1086,6 +1086,7 @@
10861086 },
10871087 "sent": {
10881088 "type": "array",
1089 "description": "The Messages record: every reminder marked sent, newest first, with the words as approved. The date's label and the party's name and role are kept as they were, so an entry reads the same after either is removed.",
10891090 "items": {
10901091 "type": "object",
10911092 "properties": {
@@ -1098,6 +1099,17 @@
10981099 "party_id": {
10991100 "type": "integer"
11001101 },
1102 "label": {
1103 "type": "string",
1104 "description": "The date it was about, as named when sent."
1105 },
1106 "party_name": {
1107 "type": "string"
1108 },
1109 "party_role": {
1110 "type": "string",
1111 "description": "The party's role when sent; empty on a reminder sent before roles were kept."
1112 },
11011113 "moment": {
11021114 "enum": [
11031115 "before",
docs/TECHNICAL.md +5 −1
@@ -22,7 +22,11 @@ marked sent stay on record. Over the API: `PATCH` or `DELETE
2222
2323 Sending is simulated: *Send* records that a reminder went out and the
2424 words approved with it; nothing leaves the app. The record is shown on the
25 page, in `/api/deals/:id`, in MCP and in the terminal.
25 page (the **Messages** section of `/deals/:id`, newest first, each entry
26 opening to the approved words), in `/api/deals/:id` and the MCP `get_deal` as
27 `sent`, and in the terminal (open a deal with `o`, then `s`: the sent reminders,
28 newest first; enter opens the words; `b` goes back). The party's role is stored with the send, so an
29 entry reads the same after the party or the date is removed.
2630
2731 *Don't send* declines a reminder with a reason (1 to 200 characters), kept in
2832 `reminder_declined` and shown as "Not sent: reason · who". A declined reminder
src/db.test.ts +15 −1
@@ -64,6 +64,20 @@ test("sample deals boot looking like today, and a changed one is left alone", ()
6464 expect(again.query("SELECT value FROM app_meta WHERE key = 'sample_anchor'").get()).toEqual({ value: today() });
6565 });
6666
67 test("a reminder sent under the name Sample data does not pass as the sample's own", () => {
68 const dir = mkdtempSync(join(tmpdir(), "app-spoof-"));
69 const db = openDb(dir);
70 db.exec("DELETE FROM deal; DELETE FROM app_meta");
71 seed(db, addDays(today(), -30));
72 const orchard = db.query<{ id: number }, []>("SELECT id FROM deal WHERE address = '9 Orchard Row'").get()!.id;
73 const d = db.query<{ id: number; due: string }, [number]>("SELECT id, due FROM deadline WHERE deal_id = ?1 AND kind = 'closing'").get(orchard)!;
74 const p = db.query<{ id: number }, [number]>("SELECT id FROM party WHERE deal_id = ?1").get(orchard)!;
75 db.query("INSERT INTO reminder (deal_id, deadline_id, party_id, label, party_name, moment, due, by_name) VALUES (?1, ?2, ?3, 'Closing', 'X', 'day_of', ?4, 'Sample data')").run(orchard, d.id, p.id, d.due);
76 db.close();
77 const again = openDb(dir);
78 expect(again.query<{ due: string }, [number]>("SELECT due FROM deadline WHERE id = ?1").get(d.id)!.due).toBe(d.due);
79 });
80
6781 test("a database whose reminder columns came from another migration order still opens", () => {
6882 const dir = mkdtempSync(join(tmpdir(), "app-db-order-"));
6983 openDb(dir).close();
@@ -72,5 +86,5 @@ test("a database whose reminder columns came from another migration order still
7286 raw.close();
7387 const db = openDb(dir);
7488 expect(check(db).version).toBe(migrations.length);
75 expect(db.query("SELECT subject, body FROM reminder").all()).toEqual([]);
89 expect(db.query("SELECT subject, body FROM reminder WHERE sample = 0").all()).toEqual([]);
7690 });
src/db.ts +10
@@ -143,6 +143,16 @@ export const migrations: string[] = [
143143 UNIQUE (deadline_id, party_id, moment, due)
144144 );
145145 CREATE INDEX IF NOT EXISTS reminder_declined_deal ON reminder_declined (deal_id)`,
146 // The party's role when it was sent, kept beside their name so the record
147 // reads the same after the party is removed. Rows whose party is already
148 // gone carry '' and are shown by name alone.
149 `ALTER TABLE reminder ADD COLUMN party_role TEXT NOT NULL DEFAULT '';
150 UPDATE reminder SET party_role = coalesce((SELECT role FROM party WHERE party.id = reminder.party_id), '')`,
151 // Which sent reminders the sample data wrote itself: set only by the seed,
152 // never from a signer's name, so the sample refresh can tell its own from a
153 // person's.
154 `ALTER TABLE reminder ADD COLUMN sample INTEGER NOT NULL DEFAULT 0;
155 UPDATE reminder SET sample = 1 WHERE by_name = 'Sample data' AND deal_id IN (SELECT id FROM deal WHERE author_id = 'sample')`,
146156 ];
147157
148158 export function openDb(dir = dataDir): Database {
src/deals.test.ts +15
@@ -315,6 +315,21 @@ test("an edited contact shows in the next draft; a removed party gets none", ()
315315 expect(removeParty(db, alice, { id: lender.value.id })).toMatchObject({ ok: false, error: "not_found" });
316316 });
317317
318 test("the record keeps the party's role and the date's label after both are removed, newest first", () => {
319 const deal = open({ contractDate: addDays(today(), -5), closingDate: addDays(today(), 30) });
320 const hoa = addDeadline(db, alice, { dealId: deal.id, label: "HOA review", due: addDays(today(), 9), owes: "buyer" });
321 expect(hoa.ok).toBe(true);
322 const id = hoa.ok ? hoa.value.id : 0;
323 const buyer = deal.parties.find((p) => p.role === "buyer")!;
324 const seller = deal.parties.find((p) => p.role === "seller")!;
325 sendReminder(db, alice, { deadlineId: id, partyId: buyer.id, moment: "before" });
326 sendReminder(db, alice, { deadlineId: id, partyId: seller.id, moment: "before", subject: "Edited", body: "Mine"});
327 removeDeadline(db, alice, { id });
328 const record = fresh(deal.id).sent;
329 expect(record.map((r) => [r.party_role, r.label])).toEqual([["seller", "HOA review"], ["buyer", "HOA review"]]);
330 expect(record[0]!.body).toBe("Mine");
331 });
332
318333 test("a standard date cannot be removed; a custom one goes with its drafts, and a sent reminder stays", () => {
319334 const deal = open();
320335 const inspection = due(deal, "inspection");
src/deals.ts +6 −4
@@ -72,6 +72,8 @@ export interface Sent {
7272 /** The date's and the party's words when it was sent: they stay if either is removed. */
7373 readonly label: string;
7474 readonly party_name: string;
75 /** The party's role when it was sent; '' on a reminder sent before it was kept. */
76 readonly party_role: PartyRole | "";
7577 readonly moment: Moment;
7678 readonly due: string;
7779 readonly by_name: string;
@@ -176,7 +178,7 @@ function view(db: Database, deal: Deal): DealView {
176178 })),
177179 sent: db
178180 .query<Sent, [number]>(
179 "SELECT * FROM reminder WHERE deal_id = ?1 ORDER BY id",
181 "SELECT * FROM reminder WHERE deal_id = ?1 ORDER BY sent_at DESC, id DESC",
180182 )
181183 .all(deal.id),
182184 declined: db
@@ -664,11 +666,11 @@ export function sendReminder(
664666 if (body === undefined)
665667 return within(db, who, dealId, fail("invalid", `The message is 1 to ${BODY_MAX} characters.`));
666668 const sent = db
667 .query<Sent, [number, number, number, string, string, string, string, string, string, string]>(
668 `INSERT INTO reminder (deal_id, deadline_id, party_id, label, party_name, moment, due, by_name, subject, body) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)
669 .query<Sent, [number, number, number, string, string, string, string, string, string, string, string]>(
670 `INSERT INTO reminder (deal_id, deadline_id, party_id, label, party_name, party_role, moment, due, by_name, subject, body) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)
669671 ON CONFLICT (deadline_id, party_id, moment, due) DO UPDATE SET sent_at = sent_at RETURNING *`,
670672 )
671 .get(found.value.deal.id, deadline.id, party.id, deadline.label, party.name, input.moment, deadline.due, authorOf(who).name, subject, body)!;
673 .get(found.value.deal.id, deadline.id, party.id, deadline.label, party.name, party.role, input.moment, deadline.due, authorOf(who).name, subject, body)!;
672674 return within(db, who, dealId, ok(sent));
673675 }
674676
src/pages/deal.ts +23 −2
@@ -4,10 +4,11 @@
44 * same sheet the clock does. And the form that opens a new deal.
55 */
66
7 import { addDays, relative, spoken } from "../dates.ts";
8 import { canChange, canRemove, type DealView, type Party, type Plan, type PlannedDate } from "../deals.ts";
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";
99 import { DEFAULT_LENGTHS, PARTY_LABEL, PARTY_ROLES } from "../deadlines.ts";
1010 import { escape } from "../http.ts";
11 import { MOMENT_LABEL } from "../reminders.ts";
1112 import type { Who } from "../who.ts";
1213 import { layout } from "./layout.ts";
1314 import { badge, dueLine, owedBy, sheet, sheetId } from "./sheet.ts";
@@ -31,6 +32,22 @@ const partyControls = (p: Party, to: string): string => `<div class="party-contr
3132 <form method="post" action="/parties/${p.id}/remove"><input type="hidden" name="to" value="${escape(to)}"><button class="button button-quiet button-small" aria-label="Remove ${escape(p.name)}">Remove</button></form>
3233 </div>`;
3334
35 /** The record of what went out: each sent reminder with the words approved, newest first. */
36 function messages(deal: DealView): string {
37 if (deal.sent.length === 0) return `<p class="muted">Nothing sent yet</p>`;
38 const live = new Set(deal.deadlines.map((d) => d.id));
39 const item = (m: Sent): string => {
40 const role = m.party_role === "" ? "" : ` · ${escape(PARTY_LABEL[m.party_role])}`;
41 const removed = live.has(m.deadline_id) ? "" : " (date removed)";
42 const words =
43 m.subject === ""
44 ? `<p class="muted">The words were not kept for this one.</p>`
45 : `<div class="draft-text"><p><b>${escape(m.subject)}</b></p><p class="draft-body">${escape(m.body)}</p></div>`;
46 return `<li class="draft"><details><summary><span><b>${escape(m.party_name)}</b> <span class="muted">${role} · ${escape(m.label)}${removed}, ${escape(short(m.due))} · ${escape(MOMENT_LABEL[m.moment])}</span><br>${escape(m.subject === "" ? "(no subject kept)" : m.subject)}</span><span class="state" data-sent>Sent ${escape(short(m.sent_at.slice(0, 10)))}</span></summary>${words}</details></li>`;
47 };
48 return `<ul class="drafts">${deal.sent.map(item).join("")}</ul>`;
49 }
50
3451 export function dealPage(input: {
3552 who: Who;
3653 deal: DealView;
@@ -104,6 +121,10 @@ export function dealPage(input: {
104121 <h2>Parties</h2>
105122 ${parties}
106123 </section>
124 <section class="card" id="messages">
125 <h2>Messages</h2>
126 ${messages(deal)}
127 </section>
107128 ${deal.deadlines.map((d) => sheet(deal, d, who, on, path)).join("")}
108129 </div>
109130 ${forms}
src/routes.ts +5
@@ -167,12 +167,17 @@ export const DEAL: Schema = {
167167 },
168168 sent: {
169169 type: "array",
170 description:
171 "The Messages record: every reminder marked sent, newest first, with the words as approved. The date's label and the party's name and role are kept as they were, so an entry reads the same after either is removed.",
170172 items: {
171173 type: "object",
172174 properties: {
173175 id: { type: "integer" },
174176 deadline_id: { type: "integer" },
175177 party_id: { type: "integer" },
178 label: { type: "string", description: "The date it was about, as named when sent." },
179 party_name: { type: "string" },
180 party_role: { type: "string", description: "The party's role when sent; empty on a reminder sent before roles were kept." },
176181 moment: { enum: ["before", "day_of"] },
177182 due: DATE,
178183 by_name: { type: "string" },
src/sample.ts +22 −3
@@ -24,6 +24,8 @@ interface Sample {
2424 readonly done?: readonly string[];
2525 readonly custom?: readonly [string, number, PartyRole, string][];
2626 readonly moved?: readonly [string, number, string];
27 /** A reminder already sent, in the agent's own edited words: date kind, party role, moment, subject, body. */
28 readonly sent?: readonly [string, PartyRole, "before" | "day_of", string, string];
2729 }
2830
2931 const SAMPLES: readonly Sample[] = [
@@ -40,6 +42,13 @@ const SAMPLES: readonly Sample[] = [
4042 ["other_agent", "Jordan Ellis, Crestline Homes", "(555) 014-2290"],
4143 ],
4244 done: ["inspection", "title", "appraisal"],
45 sent: [
46 "inspection",
47 "buyer",
48 "before",
49 "Alder Lane: your inspection period ends in three days",
50 "Hi Maya and Tom,\n\nYour inspection period ends in three days. If the report left anything you want the seller to fix, tell me by tomorrow and I will put the request in writing before it closes.\n\nThanks,\nYour agent",
51 ],
4352 },
4453 {
4554 address: "77 Harbor View Dr, Unit 4B",
@@ -141,8 +150,8 @@ export function isUntouched(state: SampleState, anchor: string): boolean {
141150 /**
142151 * Bring the sample deals nobody has touched up to `on`, then remember `on` as
143152 * the day they are anchored to. A deal a person changed is left where it is.
144 * (A deal with a sent reminder is a changed one, so no reminder row needs to
145 * follow a date.)
153 * (A reminder the sample itself sent follows its date; any other sent
154 * reminder makes the deal a changed one.)
146155 */
147156 export function refresh(db: Database, on = today()): void {
148157 db.transaction(() => {
@@ -163,7 +172,7 @@ export function refresh(db: Database, on = today()): void {
163172 "SELECT count(*) AS n FROM party WHERE deal_id = ?1 AND role NOT IN ('buyer', 'seller')",
164173 ).get(deal.id)!.n;
165174 const reminders = db.query<{ n: number }, [number]>(
166 "SELECT count(*) AS n FROM reminder WHERE deal_id = ?1",
175 "SELECT count(*) AS n FROM reminder WHERE deal_id = ?1 AND sample = 0",
167176 ).get(deal.id)!.n;
168177 const state: SampleState = {
169178 address: deal.address,
@@ -186,6 +195,9 @@ export function refresh(db: Database, on = today()): void {
186195 db.query("UPDATE deal SET contract_date = ?1 WHERE id = ?2").run(shifted.contractDate, deal.id);
187196 for (const d of shifted.deadlines) db.query("UPDATE deadline SET due = ?1, done_at = ?2 WHERE id = ?3").run(d.due, d.doneAt, d.id);
188197 for (const m of shifted.moves) db.query("UPDATE deadline_move SET from_due = ?1, to_due = ?2 WHERE id = ?3").run(m.fromDue, m.toDue, m.id);
198 // The sample's sent reminder follows its date, so it stays "yesterday's".
199 const days = `+${daysBetween(anchor, on)} days`;
200 db.query("UPDATE reminder SET due = date(due, ?1), sent_at = strftime('%Y-%m-%dT%H:%M:%fZ', sent_at, ?1) WHERE deal_id = ?2 AND sample = 1").run(days, deal.id);
189201 }
190202 db.query("UPDATE app_meta SET value = ?1 WHERE key = 'sample_anchor'").run(on);
191203 }).immediate();
@@ -213,6 +225,13 @@ export function seed(db: Database, on = today()): void {
213225 db.query("UPDATE deadline SET done_at = ?1 WHERE deal_id = ?2 AND kind = ?3").run(`${addDays(on, -1)}T17:00:00.000Z`, deal.id, kind);
214226 for (const [label, days, owes, what] of s.custom ?? [])
215227 db.query("INSERT INTO deadline (deal_id, kind, label, due, owes, what) VALUES (?1, 'custom', ?2, ?3, ?4, ?5)").run(deal.id, label, addDays(on, days), owes, what);
228 if (s.sent !== undefined) {
229 const [kind, role, moment, subject, body] = s.sent;
230 const d = db.query<{ id: number; label: string; due: string }, [number, string]>("SELECT id, label, due FROM deadline WHERE deal_id = ?1 AND kind = ?2").get(deal.id, kind)!;
231 const p = db.query<{ id: number; name: string }, [number, string]>("SELECT id, name FROM party WHERE deal_id = ?1 AND role = ?2").get(deal.id, role)!;
232 const at = `${moment === "before" ? addDays(d.due, -3) : d.due}T08:30:00.000Z`;
233 db.query("INSERT INTO reminder (deal_id, deadline_id, party_id, label, party_name, party_role, moment, due, by_name, subject, body, sent_at, sample) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, 1)").run(deal.id, d.id, p.id, d.label, p.name, role, moment, d.due, SAMPLE.name, subject, body, at);
234 }
216235 if (s.moved !== undefined) {
217236 const [kind, days, reason] = s.moved;
218237 const d = db.query<{ id: number; due: string }, [number, string]>("SELECT id, due FROM deadline WHERE deal_id = ?1 AND kind = ?2").get(deal.id, kind)!;
src/server.test.ts +26
@@ -487,6 +487,32 @@ test("the clock's forms: mark done, move with a reason, send a reminder, and com
487487 expect(movedRow.due).toBe("2027-01-04");
488488 expect(movedRow.moves.map((m) => m.reason)).toEqual(["Lender extension"]);
489489 expect(after.sent.some((s) => s.deadline_id === second!.id)).toBe(true);
490 // The Messages record on the page: the edited words, escaped, with who and which moment.
491 const page = await (await api(`/deals/${deal.id}`, {}, alice)).text();
492 const messages = page.slice(page.indexOf('id="messages"'));
493 expect(messages).toContain("Edited &lt;i&gt;subject&lt;/i&gt;");
494 expect(messages).toContain("My own words");
495 expect(messages).not.toContain("<i>subject</i>");
496 expect(messages).toContain("Morning of");
497 expect(messages).toContain("3 days before");
498 expect(messages).not.toContain("Nothing sent yet");
499 });
500
501 test("a deal with nothing sent says so, and the sample's sent reminder reads back on its page", async () => {
502 const created = await api("/api/deals", { method: "POST", ...jsonBody(NEW_DEAL) }, alice);
503 const fresh = (await created.json()) as { id: number; sent: unknown[] };
504 expect(fresh.sent).toEqual([]);
505 const page = await (await api(`/deals/${fresh.id}`, {}, alice)).text();
506 expect(page).toContain("<h2>Messages</h2>");
507 expect(page).toContain('<p class="muted">Nothing sent yet</p>');
508 const deals = (await (await api("/api/deals", {}, alice)).json()) as { id: number; address: string; sent: { party_role: string; subject: string }[] }[];
509 const alder = deals.find((d) => d.address === "1418 Alder Lane")!;
510 expect(alder.sent[0]!.party_role).toBe("buyer");
511 const alderPage = await (await api(`/deals/${alder.id}`, {}, alice)).text();
512 expect(alderPage).toContain(alder.sent[0]!.subject);
513 expect(alderPage).toContain("Maya &amp; Tom Okafor");
514 // Reading follows the deal read permission: a guest sees none of it.
515 expect((await fetch(`${base}/deals/${alder.id}`)).status).toBe(401);
490516 });
491517
492518 test("POST /tick answers today's unsent reminders, and changes nothing", async () => {
src/terminal.test.ts +26 −2
@@ -7,7 +7,7 @@ import { mkdtempSync } from "node:fs";
77 import { tmpdir } from "node:os";
88 import { join } from "node:path";
99 import { addDays, today } from "./dates.ts";
10 import { addDeadline, addParty, createDeal, getDeal, listDeals, type DealView } from "./deals.ts";
10 import { addDeadline, addParty, createDeal, getDeal, listDeals, sendReminder, type DealView } from "./deals.ts";
1111 import { openDb } from "./db.ts";
1212 import { terminal, type Terminal } from "./terminal.ts";
1313 import type { Who } from "./who.ts";
@@ -113,7 +113,7 @@ test("r shows today's reminders; enter reads a draft; s sends it", () => {
113113 expect(lines(t).join("\n")).toContain("(simulated)");
114114 // A late reminder, once sent, leaves today's list; one due today stays, marked sent.
115115 expect(under(t)).not.toBe(row);
116 const sent = db.query<{ n: number }, []>("SELECT count(*) AS n FROM reminder").get()!.n;
116 const sent = db.query<{ n: number }, []>("SELECT count(*) AS n FROM reminder WHERE sample = 0").get()!.n;
117117 expect(sent).toBe(1);
118118 // `s` sent the draft unchanged: its words are what the record keeps.
119119 const kept = db.query<{ body: string }, []>("SELECT body FROM reminder").get()!.body;
@@ -264,3 +264,27 @@ test("n declines a reminder with a reason, u undoes it; anon is not asked to typ
264264 press(guest, "n", "x", "\r");
265265 expect(db.query<{ n: number }, []>("SELECT count(*) AS n FROM reminder_declined").get()!.n).toBe(before);
266266 });
267
268 test("s on a deal lists what was sent, newest first, with the words; b comes back; a guest sees nothing", () => {
269 const inspection = date("inspection");
270 const [buyer, seller] = deal().parties;
271 expect(sendReminder(db, alice, { deadlineId: inspection.id, partyId: buyer!.id, moment: "before", subject: "First <b>words</b>", body: "Hello\nfrom me" }).ok).toBe(true);
272 expect(sendReminder(db, alice, { deadlineId: inspection.id, partyId: seller!.id, moment: "before", subject: "Second words", body: "Later one" }).ok).toBe(true);
273 const t = terminal(db, alice, context);
274 goTo(t, "12 Elm St");
275 press(t, "o", "s");
276 const screen = lines(t).join("\n");
277 expect(screen).toContain("Messages — 12 Elm St");
278 expect(screen.indexOf(seller!.name)).toBeLessThan(screen.indexOf(buyer!.name));
279 expect(screen).toContain("sent " + today());
280 expect(screen).not.toContain("Later one");
281 press(t, "j", "\r");
282 expect(lines(t).join("\n")).toContain("First <b>words</b>");
283 expect(lines(t).join("\n")).toContain("from me");
284 t.press("b");
285 expect(lines(t).join("\n")).toContain("Parties");
286 const guest = terminal(db, { role: "anon" }, context);
287 press(guest, "s");
288 expect(lines(guest).join("\n")).not.toContain("First <b>words</b>");
289 expect(lines(guest).join("\n")).not.toContain("Messages —");
290 });
src/terminal.ts +31 −4
@@ -51,7 +51,7 @@ const bold = (s: string): string => `${esc}1m${s}${esc}0m`;
5151 const COLOUR: Readonly<Record<Urgency, string>> = { overdue: "31", soon: "33", later: "36", done: "2" };
5252 const tint = (u: Urgency, s: string): string => `${esc}${COLOUR[u]}m${s}${esc}0m`;
5353
54 type View = "dates" | "reminders" | "deal";
54 type View = "dates" | "reminders" | "deal" | "messages";
5555 interface Row {
5656 readonly deal: DealView;
5757 readonly date: DeadlineView;
@@ -122,10 +122,12 @@ export function terminal(
122122 const editKey = (d: Draft): string => `${d.deadline_id}:${d.party_id}:${d.moment}`;
123123 /** The draft with any words typed for it; a sent one is as it went. */
124124 const edited = (d: Draft): Draft => (unsent(d) ? { ...d, ...edits.get(editKey(d)) } : d);
125 // On a deal the cursor walks its dates, then its parties.
125 // On a deal the cursor walks its dates, then its parties; in its Messages, the sent reminders.
126126 const rowCount = (): number =>
127127 view === "reminders"
128128 ? reminderRows().length
129 : view === "messages"
130 ? (openDeal()?.sent.length ?? 0)
129131 : view === "deal"
130132 ? dateRows().length + (openDeal()?.parties.length ?? 0)
131133 : dateRows().length;
@@ -331,7 +333,16 @@ export function terminal(
331333 }
332334 if (key === "j") cursor = Math.min(cursor + 1, Math.max(0, rowCount() - 1));
333335 else if (key === "k") cursor = Math.max(cursor - 1, 0);
334 else if (key === "d" || key === "b" || key === "\x1b") {
336 else if (view === "messages" && (key === "b" || key === "\x1b")) {
337 view = "deal";
338 cursor = 0;
339 reading = undefined;
340 } else if (view === "messages" && key === "\r") reading = reading === cursor ? undefined : cursor;
341 else if (view === "deal" && key === "s") {
342 view = "messages";
343 cursor = 0;
344 reading = undefined;
345 } else if (key === "d" || key === "b" || key === "\x1b") {
335346 view = "dates";
336347 cursor = 0;
337348 } else if (key === "r") {
@@ -361,6 +372,7 @@ export function terminal(
361372 showDone = !showDone;
362373 cursor = 0;
363374 } else if (view === "reminders") onReminder(key);
375 else if (view === "messages") return;
364376 else if (!(view === "deal" && onDeal(key))) onDate(key);
365377 cursor = Math.min(cursor, Math.max(0, rowCount() - 1));
366378 }
@@ -389,6 +401,19 @@ export function terminal(
389401 if (!listed.ok) lines.push(listed.message);
390402 else if (rows.length === 0) lines.push(dim("Nothing open. Every date is done."));
391403 rows.forEach((row, i) => lines.push(dateLine(row, i, true)));
404 } else if (view === "messages") {
405 const deal = openDeal();
406 if (deal === undefined) lines.push(dim("That deal is gone."));
407 else {
408 lines.push(bold(`Messages — ${deal.address}`), "");
409 if (deal.sent.length === 0) lines.push(dim("Nothing sent yet"));
410 deal.sent.forEach((m, i) => {
411 const role = m.party_role === "" ? "" : ` (${PARTY_LABEL[m.party_role].toLowerCase()})`;
412 const text = `${m.party_name}${role} · ${m.label}, ${spoken(m.due)} · ${MOMENT_LABEL[m.moment].toLowerCase()}`;
413 lines.push(`${i === cursor ? "▸" : " "} ${dim(`sent ${m.sent_at.slice(0, 10)}`.padEnd(16))} ${i === cursor ? bold(text) : text}`);
414 if (reading === i) lines.push("", ` ${bold(m.subject === "" ? "(words not kept)" : m.subject)}`, ...m.body.split("\n").map((l) => ` ${l}`), "");
415 });
416 }
392417 } else if (view === "deal") {
393418 const deal = openDeal();
394419 if (deal === undefined) lines.push(dim("That deal is gone."));
@@ -422,8 +447,10 @@ export function terminal(
422447 const keys =
423448 view === "reminders"
424449 ? "j/k move · enter read · e edit · s send · n don't send · u undo · d dates · q quit"
450 : view === "messages"
451 ? "j/k move · enter read · b back to the deal · d dates · q quit"
425452 : view === "deal"
426 ? "j/k move · x done · u reopen · m move · a add date · p add party · e edit party · X remove date/party · D remove deal · b back · q quit"
453 ? "j/k move · s messages · x done · u reopen · m move · a add date · p add party · e edit party · X remove date/party · D remove deal · b back · q quit"
427454 : `j/k move · x done · u reopen · m move · o open deal · n new deal · c check dates · h ${showDone ? "hide" : "show"} done · r reminders · q quit`;
428455 lines.push(dim(me.role === "anon" ? `${keys} · sign in with a key the forge knows to change anything` : keys));
429456 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs