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.

Photos: the viewer stays up when its photo leaves the end of the list

Yashwanth Kamireddib4100003f95e
diff --git a/.uiverify/photos-viewer-gone.mjs b/.uiverify/photos-viewer-gone.mjs
new file mode 100644
index 0000000..62e7814
--- /dev/null
+++ b/.uiverify/photos-viewer-gone.mjs
@@ -0,0 +1,42 @@
+// The photo open in the viewer leaving the end of the list from elsewhere — hidden, deleted or
+// unfavourited on the phone, arriving with a sync — leaves the viewer on the photo before it,
+// never on an empty page with the grid hidden behind it and its keys off.
+//
+// URL=http://localhost:4203 ENGINE=webkit node .uiverify/photos-viewer-gone.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: 1280, height: 800 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null });
+const page = await ctx.newPage();
+page.on("pageerror", (e) => ok(false, `page error: ${e.message}`));
+await page.goto(URL, { waitUntil: "networkidle" });
+await openScreen(page, "Photos");
+await page.waitForTimeout(500);
+const tiles = page.locator(".px-tile");
+const ids = await tiles.evaluateAll((t) => t.map((x) => x.dataset.id));
+const last = ids.at(-1);
+await tiles.last().dblclick();
+await page.waitForTimeout(300);
+ok((await page.locator(".px-viewer").count()) === 1, `the last photo opens [${last} of ${JSON.stringify(ids)}]`);
+// Hidden on the phone; the sync lands.
+await page.evaluate(async (id) => {
+ window.__photos.find((p) => p.id === id).hidden = true;
+ const report = await window.__TAURI_INTERNALS__.invoke("sync_all");
+ window.__emit("quince://synced", { ...report, changed: ["photos"] });
+}, last);
+await page.waitForTimeout(800);
+const state = await page.evaluate(() => ({
+ viewer: !!document.querySelector(".px-viewer"),
+ behind: document.querySelector(".px-scroll")?.hasAttribute("data-behind") ?? false,
+ hidden: getComputedStyle(document.querySelector(".px-scroll")).visibility === "hidden",
+ tiles: document.querySelectorAll(".px-tile").length,
+}));
+ok(state.tiles === ids.length - 1, `the photo has left the grid [${state.tiles} tiles]`);
+ok(state.viewer || (!state.behind && !state.hidden), `the viewer is still up, or the grid is shown again — never an empty page ${JSON.stringify(state)}`);
+await b.close();
+console.log(failures ? `\n${failures} FAILED` : "\nall passed");
+process.exit(failures ? 1 : 0);
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index 88fd7e2..f4ffb6a 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -941,6 +941,13 @@ export function PhotosView() {
return;
}
}
+ // Gone from the end of the list (hidden, deleted or unfavourited elsewhere): the photo
+ // before it, as a delete here does — left past the end, the viewer drew nothing while the
+ // grid stayed hidden behind it.
+ if (open >= photos.length) {
+ setOpen(photos.length > 0 ? photos.length - 1 : null);
+ return;
+ }
openId.current = photos.ids[open] ?? null;
}, [open, photos]);