Public: anyone can read this; the crew can change it.
The browser tab says how many leads are waiting on the agent, and a lead's page is titled with the lead's name #63
Check · Review · Land · Live done — Landed and live in production.
mason/speed-to-lead:mason/56-the-browser-tab-says-how-many-leads-are → main 1 commit fork
4 files
changed +40
−5
src/pages/desk.ts +5 −4
| @@ -4,14 +4,14 @@ | ||
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | import { day, clock, consent, source, STATE_LABEL } from "./parts.ts"; |
| 7 | import { layout } from "./layout.ts"; | |
| 7 | import { deskTitle, layout } from "./layout.ts"; | |
| 8 | 8 | import { escape } from "../http.ts"; |
| 9 | 9 | import { recordLine, sourceLine } from "../clock.ts"; |
| 10 | 10 | import { isAnswer } from "../drafts.ts"; |
| 11 | 11 | import { goesLabel, RECORD_NOTE } from "../quiet.ts"; |
| 12 | 12 | import { showingWhen } from "../showings.ts"; |
| 13 | 13 | import { MAX_EMAIL_TEXT, missingLine } from "../intake.ts"; |
| 14 | import { noteLine, type DeskLead, type NewLead, type ResponseRecord, type View } from "../leads.ts"; | |
| 14 | import { inView, noteLine, type DeskLead, type NewLead, type ResponseRecord, type View } from "../leads.ts"; | |
| 15 | 15 | import type { Agent } from "../env.ts"; |
| 16 | 16 | import type { Who } from "../who.ts"; |
| 17 | 17 | |
| @@ -74,13 +74,14 @@ export function deskPage(input: { | ||
| 74 | 74 | leads.length === 0 |
| 75 | 75 | ? `<p class="empty">${q === "" ? EMPTY[show] : `No lead matches '${escape(q)}'${show === "all" ? "" : " in this view"}.`}</p>` |
| 76 | 76 | : `<ul class="desk">${leads.map((lead) => row(lead, now, agent.timeZone)).join("")}</ul>`; |
| 77 | const tab = deskTitle(counts?.needs ?? leads.filter((l) => inView(l, "needs")).length); | |
| 77 | 78 | return layout({ |
| 78 | 79 | who, |
| 79 | 80 | agent, |
| 80 | 81 | path: "/", |
| 81 | 82 | notice, |
| 82 | heading: "Desk", | |
| 83 | body: `<div id="desk" data-live="lead.added lead.changed"> | |
| 83 | tab, | |
| 84 | body: `<div id="desk" data-live="lead.added lead.changed" data-title="${escape(tab)}"> | |
| 84 | 85 | <div class="desk-head"><h1>Leads</h1>${summary}</div> |
| 85 | 86 | ${record} |
| 86 | 87 | ${search} |
src/pages/layout.ts +7 −1
| @@ -11,6 +11,10 @@ import { asset, escape } from "../http.ts"; | ||
| 11 | 11 | import { token, tokensHref } from "../tokens.ts"; |
| 12 | 12 | import type { Who } from "../who.ts"; |
| 13 | 13 | |
| 14 | /** The desk's tab title: "(N) Speed to Lead" while N leads need the agent. */ | |
| 15 | export const deskTitle = (waiting: number): string => | |
| 16 | waiting > 0 ? `(${waiting}) ${title}` : title; | |
| 17 | ||
| 14 | 18 | // The name, brokerage and license are shown to everyone on purpose: they are |
| 15 | 19 | // the advertising disclosure the messages carry. Phone and email are not; |
| 16 | 20 | // they appear only on /profile, which needs a signed-in person. |
| @@ -21,10 +25,12 @@ export function layout(input: { | ||
| 21 | 25 | agent: Agent; |
| 22 | 26 | path: string; |
| 23 | 27 | heading?: string; |
| 28 | /** A title that replaces the heading: the desk's, with the count of leads waiting. */ | |
| 29 | tab?: string; | |
| 24 | 30 | notice?: string | undefined; |
| 25 | 31 | }): string { |
| 26 | 32 | const { body, who, agent, path, notice } = input; |
| 27 | const name = input.heading === undefined ? title : `${input.heading} · ${title}`; | |
| 33 | const name = input.tab ?? (input.heading === undefined ? title : `${input.heading} · ${title}`); | |
| 28 | 34 | const door = |
| 29 | 35 | who.role === "anon" |
| 30 | 36 | ? `<a class="button button-quiet" href="/__forge/signin?to=${escape(encodeURIComponent(path))}">Sign in</a>` |
src/server.test.ts +27
| @@ -745,3 +745,30 @@ test("a lead writing in again lands on their page, and the page says so", async | ||
| 745 | 745 | expect(page).toContain("Dana P. wrote in again"); |
| 746 | 746 | expect(page).toContain("Still there?"); |
| 747 | 747 | }); |
| 748 | ||
| 749 | test("the desk's tab title counts the leads that need the agent, from the same count as the view", async () => { | |
| 750 | const { deskTitle } = await import("./pages/layout.ts"); | |
| 751 | expect(deskTitle(0)).toBe("Speed to Lead"); | |
| 752 | expect(deskTitle(1)).toBe("(1) Speed to Lead"); | |
| 753 | expect(deskTitle(7)).toBe("(7) Speed to Lead"); | |
| 754 | await api("/sample/inquiry", { method: "POST", body: form({}) }, alice); | |
| 755 | const page = await (await api("/", {}, alice)).text(); | |
| 756 | const needs = Number(page.match(/Needs you <b>(\d+)<\/b>/)![1]); | |
| 757 | expect(needs).toBeGreaterThan(0); | |
| 758 | expect(page).toContain(`<title>(${needs}) Speed to Lead</title>`); | |
| 759 | expect(page).toContain(`data-title="(${needs}) Speed to Lead"`); | |
| 760 | const filtered = await (await api("/?show=closed", {}, alice)).text(); | |
| 761 | expect(filtered).toContain(`<title>(${needs}) Speed to Lead</title>`); | |
| 762 | }); | |
| 763 | ||
| 764 | test("signed-out pages show no count in the title", async () => { | |
| 765 | const page = await (await api("/")).text(); | |
| 766 | expect(page).toContain("<title>Speed to Lead</title>"); | |
| 767 | expect(page).not.toContain("data-title"); | |
| 768 | }); | |
| 769 | ||
| 770 | test("a lead's page is titled with the lead's name, escaped", async () => { | |
| 771 | const made = await created({ ...NEW, name: "Tab <i>Name</i>" }); | |
| 772 | const page = await (await api(`/leads/${made.id}`, {}, alice)).text(); | |
| 773 | expect(page).toContain("<title>Tab <i>Name</i> · Speed to Lead</title>"); | |
| 774 | }); |
static/live.js +1
| @@ -54,6 +54,7 @@ async function refresh(types) { | ||
| 54 | 54 | for (const el of regions) { |
| 55 | 55 | const next = fresh.getElementById(el.id); |
| 56 | 56 | if (next) el.replaceWith(next); |
| 57 | if (next?.dataset.title) document.title = next.dataset.title; // the tab's count | |
| 57 | 58 | } |
| 58 | 59 | } finally { |
| 59 | 60 | refreshing = false; |
new above
offline