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.

Shared albums: no Add Photos inside one; a cover that won't load shows the album's glyph

Yashwanth Kamireddi99278b33b2ad
diff --git a/.uiverify/photos-shared.mjs b/.uiverify/photos-shared.mjs
index b60d9c7..3399185 100644
--- a/.uiverify/photos-shared.mjs
+++ b/.uiverify/photos-shared.mjs
@@ -17,9 +17,13 @@ await ctx.addInitScript(() => {
];
window.__sharedPhotos = { "SharedCollection-W": [P("s2", 1792600000), P("s1", 1792500000)], "SharedCollection-F": [P("s3", 1792000000)] };
});
+// Every cover picture the page puts up, as it puts it up (a cover that fails is replaced at once).
+await ctx.addInitScript(() => addEventListener("DOMContentLoaded", () => new MutationObserver(() => {
+ for (const img of document.querySelectorAll(".px-albums-page .px-card img")) (window.__coverSrcs ??= new Set()).add(img.getAttribute("src"));
+}).observe(document.body, { childList: true, subtree: true })));
const page = await ctx.newPage();
page.on("pageerror", (e) => { console.log(`FAIL page error: ${e.message}`); process.exitCode = 1; });
-await page.goto("http://localhost:4173", { waitUntil: "networkidle" });
+await page.goto(process.env.URL ?? "http://localhost:4173", { waitUntil: "networkidle" });
await openScreen(page, "Photos");
await page.waitForTimeout(400);
let failures = 0;
@@ -33,7 +37,11 @@ ok((await page.locator(".px-albums-head .px-span").innerText()) === "2 Shared Al
const [w, f] = await cards();
ok(/Wallpapers[\s\S]*Created by You[\s\S]*Expires November 19/.test(w ?? ""), `one of yours: its name, made by you, when it ends ${JSON.stringify(w)}`);
ok(/Family[\s\S]*Shared with You/.test(f ?? "") && !/Expires/.test(f ?? ""), `one shared with you says so ${JSON.stringify(f)}`);
-ok((await page.locator(".px-albums-page .px-card img").first().getAttribute("src"))?.includes("s2"), "each card shows its newest photo");
+ok(await page.evaluate(() => [...(window.__coverSrcs ?? [])].some((src) => src.includes("s2")) && [...window.__coverSrcs].some((src) => src.includes("s3"))), "each card shows its newest photo");
+// The test's server sends no pictures: each cover fails to load, as offline, and the album's
+// glyph takes its place rather than a broken image.
+await page.waitForTimeout(300);
+ok((await page.locator(".px-albums-page .px-card img").count()) === 0 && (await page.locator(".px-albums-page .px-card svg").count()) === 2, "a cover that won't load gives way to the album's glyph");
ok((await page.getByRole("button", { name: "New Shared Album" }).count()) === 0, "no New Shared Album: making one isn't possible from here yet");
// Opened: its photos in the grid, under its name.
@@ -53,6 +61,7 @@ const albumAfterSync = async () => { await page.evaluate(() => window.__emit?.("
await albumAfterSync();
ok((await page.locator(".px-bar h1").innerText()) === "Wallpapers", "and stays open when a sync lands (it is in no album list of yours)");
+ok((await page.getByRole("button", { name: "Add Photos" }).count()) === 0, "no Add Photos in a shared album: it would add to your library, not the album");
// Looked at, never edited.
await page.locator(".px-tile").first().click({ button: "right" });
const menu = await page.locator(".row-menu").innerText();
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index 213563f..842a4dc 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -3520,11 +3520,15 @@ export function PhotosView() {
<Plus size={15} strokeWidth={2.2} aria-hidden="true" />
</button>
</div>}
- <div className="toolbar-group">
- <button className="tool px-cap px-add" onClick={() => void choose()} title="Add photos and videos" aria-label="Add Photos">
- <ImagePlus size={16} strokeWidth={1.9} aria-hidden="true" />
- </button>
- </div>
+ {/* Adds to the library — so not offered in a shared album, where it would read as
+ adding to the album. */}
+ {!viewOnly && (
+ <div className="toolbar-group">
+ <button className="tool px-cap px-add" onClick={() => void choose()} title="Add photos and videos" aria-label="Add Photos">
+ <ImagePlus size={16} strokeWidth={1.9} aria-hidden="true" />
+ </button>
+ </div>
+ )}
{/* Search, as icloud.com's toolbar has it: names, titles, captions, keywords, years and
months, from the library on this machine — nothing typed leaves it. */}
<SearchField
diff --git a/src/screens/photos/SharedAlbums.tsx b/src/screens/photos/SharedAlbums.tsx
index 03c7ef2..b06f026 100644
--- a/src/screens/photos/SharedAlbums.tsx
+++ b/src/screens/photos/SharedAlbums.tsx
@@ -18,6 +18,14 @@ function expiry(at: number | null): string | null {
return `Expires ${new Date(at * 1000).toLocaleDateString(undefined, { month: "long", day: "numeric" })}`;
}
+/** An album's picture: its cover, or — none, or one that won't load (offline, a link Apple let
+ * lapse) — the album's plain glyph, never a broken image. */
+function Cover({ id }: { id: string | null }) {
+ const [failed, setFailed] = useState(false);
+ if (!id || failed) return <Users size={34} strokeWidth={1.6} aria-hidden="true" />;
+ return <img src={pictureSrc(id, "thumb")} alt="" loading="lazy" decoding="async" draggable={false} onError={() => setFailed(true)} />;
+}
+
export function SharedAlbums({ onError, onOpen }: { onError: (message: string) => void; onOpen: (album: SharedAlbum) => void }) {
const [albums, setAlbums] = useState<SharedAlbum[] | null>(null);
// Read again whenever a sync changed Photos: an album new, changed or gone redraws the page.
@@ -50,11 +58,7 @@ export function SharedAlbums({ onError, onOpen }: { onError: (message: string) =
return (
<button key={a.zone} type="button" role="listitem" className="px-card" aria-label={name} onClick={() => onOpen(a)}>
<span className="px-card-pic">
- {a.cover ? (
- <img src={pictureSrc(a.cover, "thumb")} alt="" loading="lazy" decoding="async" draggable={false} />
- ) : (
- <Users size={34} strokeWidth={1.6} aria-hidden="true" />
- )}
+ <Cover key={a.cover ?? ""} id={a.cover} />
</span>
<span className="px-card-name">{name}</span>
<span className="px-card-count">{a.database === "private" ? "Created by You" : "Shared with You"}</span>