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: select several — Ctrl-click, Shift-click, Ctrl-A — then add to a list, remove, export or delete them together; drag them all onto a list

Yashwanth Kamireddi11a5e11d874a
diff --git a/.uiverify/contacts-select.mjs b/.uiverify/contacts-select.mjs
new file mode 100644
index 0000000..94b5805
--- /dev/null
+++ b/.uiverify/contacts-select.mjs
@@ -0,0 +1,47 @@
+// Several contacts at once, as Contacts on the Mac: Ctrl-click adds one, Shift-click a run,
+// Ctrl-A everyone; the card shows how many, and what is done is done to them all.
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub, openScreen } from "./stub.mjs";
+const b = await engine.launch();
+const ctx = await b.newContext({ viewport: { width: 1280, height: 800 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, contactsFixture: true });
+const page = await ctx.newPage();
+page.on("dialog", (d) => d.accept());
+await page.goto("http://localhost:4173", { waitUntil: "networkidle" });
+await openScreen(page, "Contacts");
+await page.waitForTimeout(400);
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };
+const chosen = () => page.locator('.contact-row[aria-current="true"] .contact-row-name').allInnerTexts();
+const heading = () => page.locator(".contact-many h2").innerText().catch(() => "");
+
+await page.locator(".contact-row", { hasText: "Zoya Ahuja" }).click();
+await page.locator(".contact-row", { hasText: "Northfield" }).click({ modifiers: ["Control"] });
+ok(JSON.stringify(await chosen()) === JSON.stringify(["Zoya Ahuja", "Northfield University"]), `Ctrl-click adds one ${JSON.stringify(await chosen())}`);
+ok((await heading()) === "2 Contacts Selected", "and the card says how many");
+
+await page.locator(".contact-row", { hasText: "Zoya Ahuja" }).click();
+await page.locator(".contact-row", { hasText: "Northfield" }).click({ modifiers: ["Shift"] });
+ok((await chosen()).length === 3, `Shift-click takes the run between ${JSON.stringify(await chosen())}`);
+
+await page.keyboard.press("Control+a");
+ok((await chosen()).length === 4, "Ctrl-A takes everyone");
+
+await page.getByRole("button", { name: "Export vCards" }).click();
+await page.waitForTimeout(200);
+const sent = await page.evaluate(() => window.__exports?.at(-1));
+ok(sent?.guids.length === 4 && sent.fileName === "iCloud vCards.vcf", "all of them go out together");
+
+await page.locator(".contact-many").getByRole("button", { name: "Add to List" }).click();
+await page.getByRole("menuitem", { name: "Family" }).click();
+await page.waitForTimeout(150);
+const famCount = await page.locator(".contacts-lists .notes-folder-row", { hasText: "Family" }).locator(".notes-folder-count").textContent();
+ok(famCount.trim() === "4", `all of them join a list at once ${famCount}`);
+await page.waitForTimeout(900);
+const write = await page.evaluate(() => window.__listWrites?.at(-1));
+ok(write?.add?.length === 3, `only those not in it yet are sent ${JSON.stringify(write)}`);
+
+await page.locator(".contact-row", { hasText: "Amma" }).click();
+ok((await chosen()).length === 1 && !(await page.locator(".contact-many").count()), "a plain click goes back to one");
+await b.close();
+process.exitCode = failures ? 1 : 0;
diff --git a/check.sh b/check.sh
index f37bf8d..1142b79 100755
--- a/check.sh
+++ b/check.sh
@@ -64,6 +64,7 @@ step "contacts order" node .uiverify/contacts-order.mjs
step "contacts lists" node .uiverify/contacts-lists.mjs
step "drive keys" node .uiverify/drive-keys.mjs
step "contacts vcard" node .uiverify/contacts-vcard.mjs
+step "contacts select" node .uiverify/contacts-select.mjs
step "calendar alerts" node .uiverify/calendar-alerts.mjs
step "calendar repeat" node .uiverify/calendar-repeat.mjs
step "reminder add/done" node .uiverify/reminders-add-done.mjs
diff --git a/src/screens/ContactsView.tsx b/src/screens/ContactsView.tsx
index 9a16969..d7fc8a8 100644
--- a/src/screens/ContactsView.tsx
+++ b/src/screens/ContactsView.tsx
@@ -116,7 +116,11 @@ export function ContactsView() {
const [moreMenu, setMoreMenu] = useState<MenuAt | null>(null);
/** A contact being deleted while a list is open: out of the list, or gone everywhere? */
const [deleting, setDeleting] = useState<Contact | null>(null);
- const [dragging, setDragging] = useState<string | null>(null);
+ /** The people being dragged onto a list — one, or everyone selected. */
+ const [dragging, setDragging] = useState<string[] | null>(null);
+ /** More than one person selected, as Command- and Shift-click select in Contacts. */
+ const [picked, setPicked] = useState<string[]>([]);
+ const [pickMenu, setPickMenu] = useState<MenuAt | null>(null);
const [dropOn, setDropOn] = useState<string | null>(null);
/** List writes go to Apple one after another, in the order they were made. */
const queue = useRef<Promise<unknown>>(Promise.resolve());
@@ -370,6 +374,16 @@ export function ContactsView() {
() => contacts.find((c) => c.guid === openGuid) ?? null,
[contacts, openGuid]
);
+ // Who is still here of those picked — a search or a list change narrows them.
+ const pickedPeople = useMemo(() => sortedContacts(shown.filter((c) => picked.includes(c.guid))), [shown, picked]);
+ const multi = pickedPeople.length > 1;
+ const removeMany = async (people: Contact[]) => {
+ if (!window.confirm(`Delete ${people.length} contacts?\n\nThey will be deleted from Contacts on every device.`)) return;
+ setPicked([]);
+ await write(async () => {
+ for (const c of people) await api.contactDelete(c.guid);
+ });
+ };
return (
// A contact being written is always what shows; it has its own Cancel.
@@ -405,10 +419,10 @@ export function ContactsView() {
onDragLeave={() => setDropOn((d) => (d === l.guid ? null : d))}
onDrop={(e) => {
e.preventDefault();
- const person = dragging;
+ const people = dragging;
setDragging(null);
setDropOn(null);
- if (person) addToList(l, [person]);
+ if (people) addToList(l, people);
}}
/>
)
@@ -491,7 +505,19 @@ export function ContactsView() {
/>
)}
- <ul className="contact-rows">
+ <ul
+ className="contact-rows"
+ onKeyDown={(e) => {
+ // Command/Ctrl-A: everyone shown.
+ if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "a") {
+ e.preventDefault();
+ const everyone = shown.map((c) => c.guid);
+ setPicked(everyone.length > 1 ? everyone : []);
+ } else if (e.key === "Escape" && picked.length) {
+ setPicked([]);
+ }
+ }}
+ >
{sortedContacts(shown).map((contact, i, all) => (
<Fragment key={contact.guid}>
{(i === 0 || letterOf(all[i - 1]) !== letterOf(contact)) && (
@@ -503,7 +529,7 @@ export function ContactsView() {
onDragStart={(e) => {
e.dataTransfer.effectAllowed = "copy";
e.dataTransfer.setData("text/plain", displayName(contact));
- setDragging(contact.guid);
+ setDragging(picked.includes(contact.guid) ? picked : [contact.guid]);
}}
onDragEnd={() => { setDragging(null); setDropOn(null); }}
onContextMenu={(e) => {
@@ -514,8 +540,27 @@ export function ContactsView() {
>
<button
className="contact-row"
- aria-current={openGuid === contact.guid}
- onClick={() => {
+ aria-current={multi ? picked.includes(contact.guid) : openGuid === contact.guid}
+ onClick={(e) => {
+ if (e.metaKey || e.ctrlKey) {
+ // Command/Ctrl-click adds or takes away one, keeping the rest.
+ const base = picked.length ? picked : openGuid ? [openGuid] : [];
+ const next = base.includes(contact.guid) ? base.filter((g) => g !== contact.guid) : [...base, contact.guid];
+ setPicked(next.length > 1 ? next : []);
+ if (next.length === 1) setOpenGuid(next[0]);
+ return;
+ }
+ if (e.shiftKey && openGuid) {
+ // Shift-click takes everyone between the last picked and this one.
+ const order = all.map((c) => c.guid);
+ const [a, z] = [order.indexOf(openGuid), order.indexOf(contact.guid)].sort((x, y) => x - y);
+ if (a >= 0) {
+ const range = order.slice(a, z + 1);
+ setPicked(range.length > 1 ? range : []);
+ return;
+ }
+ }
+ setPicked([]);
setOpenGuid(contact.guid);
setDetail(true);
}}
@@ -725,6 +770,43 @@ export function ContactsView() {
</button>
</div>
</form>
+ ) : multi ? (
+ <div className="contact-many">
+ <div className="contact-many-faces" aria-hidden="true">
+ {pickedPeople.slice(0, 3).map((c) => <Avatar key={c.guid} contact={c} large />)}
+ </div>
+ <h2>{pickedPeople.length} Contacts Selected</h2>
+ <div className="cal-form-actions">
+ <button
+ className="quiet"
+ aria-haspopup="menu"
+ onClick={(e) => {
+ const r = e.currentTarget.getBoundingClientRect();
+ setPickMenu({ x: r.left, y: r.bottom + 4, alignRight: false });
+ }}
+ >
+ Add to List
+ </button>
+ {openList && (
+ <button className="quiet" onClick={() => { removeFromList(openList, pickedPeople.map((c) => c.guid)); setPicked([]); }}>
+ Remove from List
+ </button>
+ )}
+ <button className="quiet" onClick={() => void exportCards(pickedPeople)}>Export vCards</button>
+ <button className="quiet danger" disabled={busy} onClick={() => void removeMany(pickedPeople)}>Delete</button>
+ </div>
+ {pickMenu && (
+ <RowMenu
+ at={pickMenu}
+ onClose={() => setPickMenu(null)}
+ entries={[
+ ...lists.filter((l) => !l.guid.startsWith("pending-")).map((l) => ({ label: l.name, run: () => addToList(l, pickedPeople.map((c) => c.guid)) })),
+ ...(lists.length ? [null] : []),
+ { label: "New List\u2026", run: () => void createList("Untitled List", pickedPeople.map((c) => c.guid)) },
+ ]}
+ />
+ )}
+ </div>
) : open ? (
<>
{/* Photo and name together at the top of the card, as Contacts arranges them.
diff --git a/src/styles/app.css b/src/styles/app.css
index 1ab5f69..60686ab 100644
--- a/src/styles/app.css
+++ b/src/styles/app.css
@@ -872,6 +872,11 @@
.contact-rows:focus-within .contact-row[aria-current="true"] .avatar:not(:has(img)) { background: rgba(255, 255, 255, 0.28); color: #fff; }
.contact-row:focus-visible { outline: 3px solid var(--gold-ring); outline-offset: -1px; }
.contact-row-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+/* Several picked: their faces fanned, the count, and what can be done to all of them. */
+.contact-many { display: flex; flex-direction: column; align-items: center; gap: 14px; padding-top: 48px; text-align: center; }
+.contact-many-faces { display: flex; }
+.contact-many-faces .avatar + .avatar { margin-left: -22px; box-shadow: 0 0 0 3px var(--bg); }
+.contact-many h2 { margin: 0; font-size: var(--t-17); }
/* "me" beside this person's own card, as Contacts marks it. */
.contact-me { margin-left: auto; color: var(--text-3); font-size: var(--t-11); }
.contact-rows:focus-within .contact-row[aria-current="true"] .contact-me { color: rgba(255, 255, 255, 0.82); }