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

Merged opened this

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

Merged

mason/speed-to-lead:mason/56-the-browser-tab-says-how-many-leads-are → main 1 commit fork

  • Merged. mason/56-the-browser-tab-says-how-many-leads-are was merged into main as efeafb7.

Review

Sign in to review this change.
4 files changed +40 −5
src/pages/desk.ts +5 −4
@@ -4,14 +4,14 @@
44 */
55
66 import { day, clock, consent, source, STATE_LABEL } from "./parts.ts";
7 import { layout } from "./layout.ts";
7 import { deskTitle, layout } from "./layout.ts";
88 import { escape } from "../http.ts";
99 import { recordLine, sourceLine } from "../clock.ts";
1010 import { isAnswer } from "../drafts.ts";
1111 import { goesLabel, RECORD_NOTE } from "../quiet.ts";
1212 import { showingWhen } from "../showings.ts";
1313 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";
1515 import type { Agent } from "../env.ts";
1616 import type { Who } from "../who.ts";
1717
@@ -74,13 +74,14 @@ export function deskPage(input: {
7474 leads.length === 0
7575 ? `<p class="empty">${q === "" ? EMPTY[show] : `No lead matches '${escape(q)}'${show === "all" ? "" : " in this view"}.`}</p>`
7676 : `<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);
7778 return layout({
7879 who,
7980 agent,
8081 path: "/",
8182 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)}">
8485 <div class="desk-head"><h1>Leads</h1>${summary}</div>
8586 ${record}
8687 ${search}
src/pages/layout.ts +7 −1
@@ -11,6 +11,10 @@ import { asset, escape } from "../http.ts";
1111 import { token, tokensHref } from "../tokens.ts";
1212 import type { Who } from "../who.ts";
1313
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
1418 // The name, brokerage and license are shown to everyone on purpose: they are
1519 // the advertising disclosure the messages carry. Phone and email are not;
1620 // they appear only on /profile, which needs a signed-in person.
@@ -21,10 +25,12 @@ export function layout(input: {
2125 agent: Agent;
2226 path: string;
2327 heading?: string;
28 /** A title that replaces the heading: the desk's, with the count of leads waiting. */
29 tab?: string;
2430 notice?: string | undefined;
2531 }): string {
2632 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}`);
2834 const door =
2935 who.role === "anon"
3036 ? `<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
745745 expect(page).toContain("Dana P. wrote in again");
746746 expect(page).toContain("Still there?");
747747 });
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 &lt;i&gt;Name&lt;/i&gt; · Speed to Lead</title>");
774 });
static/live.js +1
@@ -54,6 +54,7 @@ async function refresh(types) {
5454 for (const el of regions) {
5555 const next = fresh.getElementById(el.id);
5656 if (next) el.replaceWith(next);
57 if (next?.dataset.title) document.title = next.dataset.title; // the tab's count
5758 }
5859 } finally {
5960 refreshing = false;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs