Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Contacts: a company's card goes by the company

Yashwanth Kamireddi2466138ffa78
diff --git a/.uiverify/contacts-company.mjs b/.uiverify/contacts-company.mjs
new file mode 100644
index 0000000..2a4411f
--- /dev/null
+++ b/.uiverify/contacts-company.mjs
@@ -0,0 +1,33 @@
+// A company's card goes by the company, as Contacts shows it: in the list, at the top of the
+// card, and in the search across everything — with the person named on it underneath. It used
+// to read as the person, filed under the company's letter, with the company nowhere.
+//
+// URL=http://localhost:4203 ENGINE=webkit node .uiverify/contacts-company.mjs
+import { engine, engineName } from "./engine.mjs";
+import { SERVICES, installStub, openScreen } from "./stub.mjs";
+const URL = process.env.URL ?? "http://localhost:4173";
+const b = await engine.launch();
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${engineName} ${m}`); if (!p) failures++; };
+const ctx = await b.newContext({ viewport: { width: 1200, height: 800 } });
+await ctx.addInitScript(() => {
+ window.__contactsExtra = [{ guid: "c9", firstName: "Ravi", lastName: "Menon", company: "Bluepine Logistics", isCompany: true,
+ birthday: null, notes: null, etag: null, methods: [{ kind: "phone", label: "work", value: "+1 555 010 0142" }] }];
+});
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, contactsFixture: true });
+const page = await ctx.newPage();
+page.on("pageerror", (e) => ok(false, `page error: ${e.message}`));
+await page.goto(URL, { waitUntil: "networkidle" });
+await openScreen(page, "Contacts");
+await page.waitForTimeout(400);
+const rows = (await page.locator(".contact-rows > li").allInnerTexts()).map((t) => t.replace(/\s+/g, " ").trim());
+ok(rows.some((t) => t.endsWith("Bluepine Logistics")) && !rows.some((t) => /Ravi Menon$/.test(t)), `the list names the company ${JSON.stringify(rows)}`);
+await page.locator(".contact-rows > li", { hasText: "Bluepine" }).first().click();
+await page.waitForTimeout(250);
+const head = await page.locator(".contact-head-names h2").innerText();
+ok(head === "Bluepine Logistics", `the card is headed by the company [${head}]`);
+const under = await page.locator(".contact-head-names .contact-company").allInnerTexts();
+ok(under.includes("Ravi Menon"), `with the person named underneath ${JSON.stringify(under)}`);
+await b.close();
+console.log(failures ? `\n${failures} FAILED` : "\nall passed");
+process.exit(failures ? 1 : 0);
diff --git a/src/lib/ipc.ts b/src/lib/ipc.ts
index 944dc27..4c9549e 100644
--- a/src/lib/ipc.ts
+++ b/src/lib/ipc.ts
@@ -879,6 +879,8 @@ export type SearchGroup = { app: string; count: number; hits: SearchHit[] };
export type SearchFound = { seq: number; groups: SearchGroup[] };
export function displayName(c: Contact): string {
+ // A company's card goes by the company, as Contacts shows it, whoever is named on it.
+ if (c.isCompany && c.company?.trim()) return c.company.trim();
const full = [c.firstName, c.middleName, c.lastName].filter(Boolean).join(" ").trim();
if (full) return full;
if (c.company?.trim()) return c.company;
diff --git a/src/screens/ContactsView.tsx b/src/screens/ContactsView.tsx
index eafed3a..80d7109 100644
--- a/src/screens/ContactsView.tsx
+++ b/src/screens/ContactsView.tsx
@@ -90,11 +90,18 @@ const ADDABLE = [
/** The whole name, as the top of a card shows it: prefix and suffix included. */
function fullName(c: Contact): string {
+ if (c.isCompany && c.company?.trim()) return c.company.trim();
const name = [c.prefix, c.firstName, c.middleName, c.lastName].filter(Boolean).join(" ");
if (!name.trim()) return displayName(c);
return c.suffix ? `${name}, ${c.suffix}` : name;
}
+/** The person's own name on a card, prefix and suffix included; empty when it has none. */
+function personName(c: Contact): string {
+ const name = [c.prefix, c.firstName, c.middleName, c.lastName].filter(Boolean).join(" ").trim();
+ return name && c.suffix ? `${name}, ${c.suffix}` : name;
+}
+
const blank = (): Contact => ({
guid: "",
firstName: null,
@@ -1498,6 +1505,10 @@ export function ContactsView() {
{open.company && !open.isCompany && (
<p className="contact-company">{open.company}</p>
)}
+ {/* A company's card is headed by the company; the person on it comes under. */}
+ {open.isCompany && open.company?.trim() && personName(open) && (
+ <p className="contact-company">{personName(open)}</p>
+ )}
{me === open.guid && <p className="contact-company">My Card</p>}
</div>
</div>