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: fix months shown twice and another view's photos; no text selection; full picture

Yashwanth Kamireddi00e1cdbced95
diff --git a/.uiverify/photos-real.mjs b/.uiverify/photos-real.mjs
new file mode 100644
index 0000000..6bf3b5f
--- /dev/null
+++ b/.uiverify/photos-real.mjs
@@ -0,0 +1,46 @@
+// Faults seen in the real window: a slow read of one view landing after another was chosen
+// drew its photos under the other's title; Ctrl+A with the app list focused selected the
+// page's text; the viewer showed the screen-sized picture, not the whole one.
+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 });
+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 openScreen(page, "Photos");
+await page.waitForTimeout(400);
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };
+
+await page.evaluate(() => { window.__slowView = "recents"; });
+await page.locator(".px-source", { hasText: "Recents" }).click();
+await page.locator(".px-source", { hasText: "Favorites" }).click();
+await page.waitForTimeout(900);
+ok((await page.locator(".px-bar h1").innerText()) === "Favorites" && (await page.locator(".px-tile").count()) === 1,
+ `a slow read of another view does not take the screen (${await page.locator(".px-tile").evaluateAll((t) => t.map((x) => x.dataset.id).join())} under Favorites)`);
+await page.evaluate(() => { window.__slowView = null; });
+// The same without the wait: from Recents (by date added) straight to Favorites, the months
+// are each other's and never come twice.
+await page.locator(".px-source", { hasText: "Recents" }).click();
+await page.locator(".px-source", { hasText: "Favorites" }).click();
+await page.waitForTimeout(400);
+const titles = await page.locator(".px-month-title").allInnerTexts();
+ok(new Set(titles).size === titles.length && (await page.locator(".px-tile").count()) === 1,
+ `switching views at once leaves no month twice, nor another view's photos ${JSON.stringify(titles)}`);
+await page.locator(".px-source", { hasText: "Library" }).click();
+await page.waitForTimeout(300);
+
+await page.locator(".nav-item", { hasText: "Photos" }).focus();
+await page.keyboard.press("Control+a");
+await page.waitForTimeout(100);
+ok((await page.evaluate(() => window.getSelection()?.toString() ?? "")) === "", "Ctrl+A with the app list focused selects no text");
+ok((await page.locator('.px-tile[aria-selected="true"]').count()) === 5, "and selects every photo");
+await page.keyboard.press("Escape");
+
+await page.locator(".px-tile").nth(1).dblclick();
+await page.waitForTimeout(500);
+ok(/full/.test((await page.locator(".px-sharp").getAttribute("src")) ?? ""), "an opened photo fetches the whole picture at once, not only when zoomed");
+await b.close();
+process.exitCode = failures ? 1 : (process.exitCode ?? 0);
diff --git a/.uiverify/photos.mjs b/.uiverify/photos.mjs
index 401f0b6..db9d573 100644
--- a/.uiverify/photos.mjs
+++ b/.uiverify/photos.mjs
@@ -36,10 +36,10 @@ await page.waitForTimeout(200);
await page.locator(".px-tile").first().dblclick();
await page.waitForTimeout(150);
ok((await page.locator(".px-viewer").count()) === 1, "a photo opens in the viewer");
-const first = await page.locator(".px-stage img").getAttribute("src");
+const first = await page.locator(".px-stage .px-shown").getAttribute("src");
await page.keyboard.press("ArrowRight");
await page.waitForTimeout(100);
-const second = await page.locator(".px-stage img").getAttribute("src");
+const second = await page.locator(".px-stage .px-shown").getAttribute("src");
ok(first && second && first !== second && /medium/.test(second), "the right arrow goes to the next photo, at screen size");
await page.getByRole("button", { name: "Download" }).click();
await page.waitForTimeout(200);
@@ -56,7 +56,7 @@ ok(JSON.stringify(flags) === JSON.stringify(["p2:favorite:true", "p2:favorite:fa
page.once("dialog", (d) => void d.accept());
await page.getByRole("button", { name: "Delete", exact: true }).click();
await page.waitForTimeout(300);
-const next = await page.locator(".px-stage img, .px-stage video").first().getAttribute("src");
+const next = await page.locator(".px-stage .px-shown").first().getAttribute("src");
ok(/p3|p4/.test(next ?? "") && (await page.locator(".px-tile").count()) === 4, "Delete, once agreed, takes it out and shows the next");
// A video shows its still; Play opens it in the computer's own player.
if (await page.getByRole("button", { name: "Play in your video player" }).count()) {
diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjs
index ca63d53..55c9779 100644
--- a/.uiverify/stub.mjs
+++ b/.uiverify/stub.mjs
@@ -322,7 +322,10 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
hidden: all.filter((p) => !p.deleted && p.hidden),
};
if (cmd === "photos_counts") return Object.entries(views).map(([k, v]) => [k, v.length]);
- return views[args.view] ?? [];
+ // A read that takes its time, so a test can have it land after another view is chosen.
+ const answer = (views[args.view] ?? []).map((p) => ({ ...p }));
+ if (window.__slowView === args.view) return new Promise((r) => setTimeout(() => r(answer), 600));
+ return answer;
}
case "photos_albums": {
const albums = (window.__albums ??= [{ id: "AL1", name: "Trips", position: 0, changeTag: null, items: ["p4", "p2"] }]);
diff --git a/check.sh b/check.sh
index 988e88c..57ab059 100755
--- a/check.sh
+++ b/check.sh
@@ -62,6 +62,7 @@ step "photos keys" node .uiverify/photos-keys.mjs
step "photos sort" node .uiverify/photos-sort.mjs
step "slideshow" node .uiverify/photos-show.mjs
step "photo captions" node .uiverify/photos-caption.mjs
+step "photos real faults" node .uiverify/photos-real.mjs
step "notes delete" node .uiverify/notes-delete.mjs
step "empty today" node .uiverify/reminders-empty.mjs
step "calendar keys" node .uiverify/calendar-keys.mjs
@@ -107,6 +108,7 @@ step "webkit: keys" env ENGINE=webkit node .uiverify/photos-keys.mjs
step "webkit: sort" env ENGINE=webkit node .uiverify/photos-sort.mjs
step "webkit: slideshow" env ENGINE=webkit node .uiverify/photos-show.mjs
step "webkit: captions" env ENGINE=webkit node .uiverify/photos-caption.mjs
+step "webkit: real faults" env ENGINE=webkit node .uiverify/photos-real.mjs
step "webkit: delete" env ENGINE=webkit node .uiverify/notes-delete.mjs
step "webkit: row hover" env ENGINE=webkit node .uiverify/row-hover.mjs
step "webkit: fold" env ENGINE=webkit node .uiverify/sidebar-fold.mjs
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index 0e81ef3..2c9174d 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -239,7 +239,8 @@ export function PhotosView() {
/** An album open instead of a view. */
const [album, setAlbum] = useState<PhotoAlbum | null>(null);
const [albums, setAlbums] = useState<[PhotoAlbum, number][]>([]);
- const [photos, setPhotos] = useState<Photo[] | null>(null);
+ /** The view's photos as read; `photos`, below, is them in the order chosen to show. */
+ const [raw, setPhotos] = useState<Photo[] | null>(null);
const [counts, setCounts] = useState<Partial<Record<PhotoView, number>>>({});
const [error, setError] = useState<string | null>(null);
const [zoom, setZoom] = useState(1);
@@ -262,8 +263,6 @@ export function PhotosView() {
const [sorts, setSorts] = useState(readSorts);
const sortable = !album && view !== "recentlyDeleted";
const sort = sortable ? (sorts[view] ?? defaultSort(view)) : null;
- const sortRef = useRef(sort);
- sortRef.current = sort;
const chooseSort = (next: Sort) => {
setSorts((all) => {
const was = { ...all, [view]: next };
@@ -275,17 +274,26 @@ export function PhotosView() {
return was;
});
};
- useEffect(() => {
- if (sort) setPhotos((list) => (list ? sortList(list, sort) : list));
- }, [sort?.by, sort?.oldest]); // eslint-disable-line react-hooks/exhaustive-deps
+ // Sorted where it is drawn, in the same render as the months made from it. Sorted after the
+ // render instead, a view's first frame grouped one order by another's dates: months came
+ // twice ("December 2025" four times over), and the repeated keys left stale months on screen.
+ const photos = useMemo(
+ () => (raw && sort ? sortList(raw, sort) : raw),
+ [raw, sort?.by, sort?.oldest], // eslint-disable-line react-hooks/exhaustive-deps
+ );
+ // Reads can pass each other: a sync's read of one view can land after another view was
+ // chosen. Only the newest read may draw, or a view shows another's photos under its title.
+ const reads = useRef(0);
const read = useCallback(async () => {
+ const mine = ++reads.current;
const [list, c, a] = await Promise.all([
album ? api.photosInAlbum(album.id) : api.photosList(view),
api.photosCounts(),
api.photosAlbums(),
]);
- setPhotos(sortRef.current ? sortList(list, sortRef.current) : list);
+ if (mine !== reads.current) return;
+ setPhotos(list);
setCounts(Object.fromEntries(c));
setAlbums(a);
// An album deleted elsewhere is not left open, empty.
@@ -469,9 +477,11 @@ export function PhotosView() {
unzoom();
setSharp(null);
}, [shown?.id]);
+ // The whole picture, not the screen-sized one, as Photos shows a photo: fetched as soon as
+ // it opens (once, then from disk) and laid over the quick one when it has arrived.
useEffect(() => {
- if (lens.k > 1.15 && shown && shown.kind !== "video") setSharp(shown.id);
- }, [lens.k > 1.15, shown?.id]); // eslint-disable-line react-hooks/exhaustive-deps
+ if (shown && shown.kind !== "video") setSharp(shown.id);
+ }, [shown?.id]); // eslint-disable-line react-hooks/exhaustive-deps
// A pinch or Ctrl + wheel: the page must not zoom too, so this listener is not passive.
useEffect(() => {
const el = stage.current;
@@ -773,9 +783,12 @@ export function PhotosView() {
const onKey = (e: KeyboardEvent) => {
const t = e.target as HTMLElement | null;
if (t?.closest?.("input, textarea, [contenteditable], .row-menu, [role=dialog]") || naming) return;
- if (!t?.closest?.(".px") && t !== document.body) return;
const list = photos ?? [];
const ctrl = e.ctrlKey || e.metaKey;
+ // Ctrl+A is the photos' wherever the focus rests on this screen — the app list keeps it
+ // after Photos is chosen there — never the page's text.
+ const selectAll = ctrl && e.key.toLowerCase() === "a";
+ if (!selectAll && !t?.closest?.(".px") && t !== document.body) return;
if (ctrl && e.key.toLowerCase() === "a") {
setChosen(new Set(list.map((p) => p.id)));
} else if (e.key === "Escape" && chosen.size) {
@@ -1343,7 +1356,7 @@ export function PhotosView() {
}} style={{ "--across": across } as React.CSSProperties}>
{months.map((m, k) => (
<Month
- key={`${view}/${album?.id ?? ""}/${m.label}`}
+ key={`${view}/${album?.id ?? ""}/${k}/${m.label}`}
label={m.label}
items={m.items}
chosen={chosen}
diff --git a/src/styles/photos.css b/src/styles/photos.css
index 2c83876..3c09ac6 100644
--- a/src/styles/photos.css
+++ b/src/styles/photos.css
@@ -6,6 +6,9 @@
.content:has(.px) { display: flex; flex-direction: column; overflow: hidden; padding-top: 18px; }
.px {
+ /* An app's own words are not text to select, as in Photos; a field still takes typing. */
+ -webkit-user-select: none;
+ user-select: none;
flex: 1;
min-height: 0;
display: grid;
@@ -458,3 +461,4 @@
.px-caption::placeholder { color: var(--text-3); font-weight: 500; }
.px-caption:hover:not(:read-only) { background: color-mix(in srgb, var(--text) 6%, transparent); }
.px-caption:focus { background: var(--field, transparent); box-shadow: 0 0 0 2px var(--accent-ring); }
+.px input, .px textarea { -webkit-user-select: text; user-select: text; }