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: star ratings and Rated, as icloud.com keeps them

Yashwanth Kamireddi7822bb46bbed
diff --git a/.uiverify/photos-rating.mjs b/.uiverify/photos-rating.mjs
new file mode 100644
index 0000000..24f7d56
--- /dev/null
+++ b/.uiverify/photos-rating.mjs
@@ -0,0 +1,45 @@
+// Star ratings, as icloud.com keeps them: a rated photo carries its stars on its tile; Info's
+// stars set them (the same again takes them away); Rated holds the rated, grouped by stars.
+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++; };
+
+ok((await page.locator(".px-tile .px-stars").allInnerTexts()).join() === "5★", "a rated photo carries its stars on its tile");
+await page.locator(".px-source", { hasText: "Rated" }).click();
+await page.waitForTimeout(250);
+ok((await page.locator(".px-month-title").allInnerTexts()).join() === "5 Stars" && (await page.locator(".px-tile").count()) === 1,
+ "Rated holds the rated, under how many stars");
+await page.locator(".px-source", { hasText: "Library" }).click();
+await page.waitForTimeout(250);
+
+await page.locator(".px-tile").nth(1).dblclick();
+await page.waitForTimeout(600);
+if (!(await page.locator(".px-info").count())) await page.keyboard.press("i");
+await page.getByRole("radio", { name: "3 stars" }).click();
+await page.waitForTimeout(200);
+ok(JSON.stringify(await page.evaluate(() => window.__ratings?.at(-1))) === JSON.stringify({ id: "p2", rating: 3 }), "Info's third star rates it three");
+ok((await page.locator(".px-star.is-on").count()) === 3, "and three stars light at once");
+await page.keyboard.press("Escape");
+await page.waitForTimeout(650);
+await page.locator(".px-source", { hasText: "Rated" }).click();
+await page.waitForTimeout(250);
+ok((await page.locator(".px-month-title").allInnerTexts()).join() === "5 Stars,3 Stars", `and Rated has it under 3 Stars ${JSON.stringify(await page.locator(".px-month-title").allInnerTexts())}`);
+await page.locator(".px-tile").nth(1).dblclick();
+await page.waitForTimeout(600);
+await page.getByRole("radio", { name: "3 stars" }).click();
+await page.waitForTimeout(300);
+ok((await page.evaluate(() => window.__ratings.at(-1).rating)) === 0, "the same star again takes the rating away");
+await page.keyboard.press("Escape");
+await page.waitForTimeout(650);
+ok((await page.locator(".px-tile").count()) === 1, "and the photo leaves Rated");
+await b.close();
+process.exitCode = failures ? 1 : (process.exitCode ?? 0);
diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjs
index 21116d4..7582017 100644
--- a/.uiverify/stub.mjs
+++ b/.uiverify/stub.mjs
@@ -313,13 +313,14 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
favorite: false, hidden: false, deleted: false, deletedAt: null, subtype: 0, changeTag: null, ...extra });
const all = (window.__photos ??= [
P("p1", 1792500000, { favorite: true }), P("p2", 1792400000), P("p3", 1792300000, { kind: "video", duration: 12.4, uti: "public.mpeg-4", filename: "clip.mp4" }),
- P("p4", 1789900000, { addedAt: 1792700000 }), P("p5", 1789800000), P("p6", 1789700000, { deleted: true, deletedAt: 1792600000, expungeAt: Math.floor(Date.now() / 1000) + 2 * 86400 + 600 }),
+ P("p4", 1789900000, { addedAt: 1792700000 }), P("p5", 1789800000, { rating: 5 }), P("p6", 1789700000, { deleted: true, deletedAt: 1792600000, expungeAt: Math.floor(Date.now() / 1000) + 2 * 86400 + 600 }),
]);
const live = all.filter((p) => !p.deleted && !p.hidden);
const views = {
library: live, recents: live, favorites: live.filter((p) => p.favorite), videos: live.filter((p) => p.kind === "video"),
screenshots: live.filter((p) => p.uti === "public.png"), recentlyDeleted: all.filter((p) => p.deleted),
hidden: all.filter((p) => !p.deleted && p.hidden),
+ rated: live.filter((p) => (p.rating ?? 0) > 0).sort((a, b) => b.rating - a.rating || b.takenAt - a.takenAt),
};
if (cmd === "photos_counts") return Object.entries(views).map(([k, v]) => [k, v.length]);
// A read that takes its time, so a test can have it land after another view is chosen.
@@ -365,6 +366,12 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
}
return p;
}
+ case "photo_set_rating": {
+ (window.__ratings ??= []).push(args);
+ const p = (window.__photos ?? []).find((x) => x.id === args.id);
+ if (p) p.rating = args.rating;
+ return p;
+ }
case "photo_set_text": {
(window.__texts ??= []).push(args);
const p = (window.__photos ?? []).find((x) => x.id === args.id);
diff --git a/check.sh b/check.sh
index a5d540d..1e26753 100755
--- a/check.sh
+++ b/check.sh
@@ -64,6 +64,7 @@ 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 "whole photos" node .uiverify/photos-fit.mjs
+step "star ratings" node .uiverify/photos-rating.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
@@ -111,6 +112,7 @@ 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: whole photos" env ENGINE=webkit node .uiverify/photos-fit.mjs
+step "webkit: ratings" env ENGINE=webkit node .uiverify/photos-rating.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/crates/quince-core/src/photos.rs b/crates/quince-core/src/photos.rs
index dfe9d75..f608a68 100644
--- a/crates/quince-core/src/photos.rs
+++ b/crates/quince-core/src/photos.rs
@@ -73,6 +73,9 @@ pub struct Photo {
/// Its caption, the longer words under the title (`extendedDescEnc`).
#[serde(default)]
pub caption: Option<String>,
+ /// Its star rating, 0 (none) to 5.
+ #[serde(default)]
+ pub rating: i64,
/// Photos' subtype: 1 and 3 mark screenshots and the like (`assetSubtypeV2`).
pub subtype: i64,
/// The asset's change tag, for writing back to it.
@@ -119,11 +122,13 @@ pub enum View {
Recents,
/// Hidden from every other view, as Photos' Hidden album.
Hidden,
+ /// Those given stars, the most first.
+ Rated,
RecentlyDeleted,
}
const COLUMNS: &str = "id, master, taken_at, added_at, kind, width, height, duration, filename, \
- size, uti, favorite, hidden, deleted, deleted_at, subtype, change_tag, expunge_at, title, caption";
+ size, uti, favorite, hidden, deleted, deleted_at, subtype, change_tag, expunge_at, title, caption, rating";
fn row_to_photo(r: &rusqlite::Row<'_>) -> rusqlite::Result<Photo> {
Ok(Photo {
@@ -147,6 +152,7 @@ fn row_to_photo(r: &rusqlite::Row<'_>) -> rusqlite::Result<Photo> {
expunge_at: r.get(17)?,
title: r.get(18)?,
caption: r.get(19)?,
+ rating: r.get(20)?,
})
}
@@ -158,8 +164,8 @@ impl Library {
let mut stmt = tx.prepare(
"INSERT INTO photos (id, master, taken_at, added_at, kind, width, height, duration,
filename, size, uti, favorite, hidden, deleted, deleted_at,
- subtype, change_tag, expunge_at, title, caption)
- VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20)
+ subtype, change_tag, expunge_at, title, caption, rating)
+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20, ?21)
ON CONFLICT(id) DO UPDATE SET
master = excluded.master, taken_at = excluded.taken_at,
added_at = excluded.added_at, kind = excluded.kind, width = excluded.width,
@@ -169,7 +175,7 @@ impl Library {
deleted = excluded.deleted, deleted_at = excluded.deleted_at,
subtype = excluded.subtype, change_tag = excluded.change_tag,
expunge_at = excluded.expunge_at, title = excluded.title,
- caption = excluded.caption",
+ caption = excluded.caption, rating = excluded.rating",
)?;
for p in photos {
stmt.execute(params![
@@ -192,7 +198,8 @@ impl Library {
p.change_tag,
p.expunge_at,
p.title,
- p.caption
+ p.caption,
+ p.rating
])?;
}
}
@@ -247,6 +254,10 @@ impl Library {
"COALESCE(added_at, taken_at) DESC",
),
View::Hidden => ("deleted = 0 AND hidden = 1", "taken_at DESC"),
+ View::Rated => (
+ "deleted = 0 AND hidden = 0 AND rating > 0",
+ "rating DESC, taken_at DESC",
+ ),
View::RecentlyDeleted => ("deleted = 1", "COALESCE(deleted_at, taken_at) DESC"),
}
}
@@ -269,6 +280,7 @@ impl Library {
View::Videos,
View::Screenshots,
View::Hidden,
+ View::Rated,
View::RecentlyDeleted,
] {
// Counted where the rows are: a library of twenty thousand is not read seven times
@@ -505,6 +517,7 @@ mod tests {
expunge_at: None,
title: None,
caption: None,
+ rating: 0,
}
}
diff --git a/crates/quince-core/src/schema.rs b/crates/quince-core/src/schema.rs
index 7331a44..90cdf2c 100644
--- a/crates/quince-core/src/schema.rs
+++ b/crates/quince-core/src/schema.rs
@@ -462,4 +462,9 @@ pub const MIGRATIONS: &[&str] = &[
ALTER TABLE photos ADD COLUMN caption TEXT;
UPDATE sync_state SET token = NULL WHERE service = 'photos';
"#,
+ // A photo's star rating; Photos read again so every photo has its own.
+ r#"
+ ALTER TABLE photos ADD COLUMN rating INTEGER NOT NULL DEFAULT 0;
+ UPDATE sync_state SET token = NULL WHERE service = 'photos';
+ "#,
];
diff --git a/crates/quince-icloud/src/photos.rs b/crates/quince-icloud/src/photos.rs
index 8b321b5..7848ae6 100644
--- a/crates/quince-icloud/src/photos.rs
+++ b/crates/quince-icloud/src/photos.rs
@@ -160,6 +160,7 @@ pub fn photo_of(asset: &Value, master: &Value) -> Option<Photo> {
subtype: field::int(asset, "assetSubtypeV2").unwrap_or(0),
title: decoded(asset, "captionEnc"),
caption: decoded(asset, "extendedDescEnc"),
+ rating: field::int(asset, "rating").unwrap_or(0).clamp(0, 5),
expunge_at: (field::int(asset, "isDeleted") == Some(1))
.then(|| millis(asset, "dateExpunged"))
.flatten(),
@@ -187,6 +188,7 @@ fn with_asset(mut p: Photo, asset: &Value) -> Photo {
};
p.title = decoded(asset, "captionEnc");
p.caption = decoded(asset, "extendedDescEnc");
+ p.rating = field::int(asset, "rating").unwrap_or(0).clamp(0, 5);
p.expunge_at = if p.deleted {
millis(asset, "dateExpunged").or(p.expunge_at)
} else {
@@ -396,6 +398,28 @@ pub async fn set_title_and_caption(
.await
}
+/// A photo's star rating set, as icloud.com's Info sets it: `rating`, 0 (none) to 5, against
+/// the asset's change tag. Answers the asset as it now is.
+pub async fn set_rating(
+ http: &reqwest::Client,
+ ckdatabasews_root: &str,
+ params: Vec<(String, String)>,
+ asset: &str,
+ change_tag: Option<&str>,
+ rating: i64,
+) -> Result<Value> {
+ let client = ZoneClient::new(http, ckdatabasews_root, CONTAINER, params);
+ client
+ .update_record(
+ ZONE,
+ asset,
+ "CPLAsset",
+ change_tag,
+ serde_json::json!({ "rating": { "value": rating.clamp(0, 5) } }),
+ )
+ .await
+}
+
/// An album's name as Photos writes it: base64 of its UTF-8 bytes, untyped.
fn album_name(name: &str) -> String {
base64::engine::general_purpose::STANDARD.encode(name.as_bytes())
diff --git a/probe/examples/photos_rating_roundtrip.rs b/probe/examples/photos_rating_roundtrip.rs
new file mode 100644
index 0000000..26ef92c
--- /dev/null
+++ b/probe/examples/photos_rating_roundtrip.rs
@@ -0,0 +1,35 @@
+//! Live, on a wallpaper he named as a throwaway: a star rating set through Quince's own
+//! set_rating, read back from Apple, then cleared. Leaves the photo as it was.
+use anyhow::{anyhow, Result};
+use quince_icloud::photos::{self, CONTAINER, ZONE};
+
+#[tokio::main]
+async fn main() -> Result<()> {
+ let asset = std::env::args().nth(1).ok_or_else(|| anyhow!("asset id"))?;
+ let dir = std::path::PathBuf::from(std::env::var("HOME")?).join(".local/share/quince-probe");
+ let mut client = quince_auth::Client::new(&dir)?;
+ if !client.resume().await? {
+ return Err(anyhow!("no session"));
+ }
+ let ck = client
+ .session()
+ .service_url("ckdatabasews")
+ .ok_or_else(|| anyhow!("no ck"))?;
+ let (http, p) = (client.http().clone(), client.service_params());
+ let zc = quince_icloud::cloudkit::ZoneClient::new(&http, &ck, CONTAINER, p.clone());
+ let rating = |r: &serde_json::Value| r.pointer("/fields/rating/value").cloned();
+ let before = zc
+ .lookup_record(ZONE, &asset)
+ .await?
+ .ok_or_else(|| anyhow!("gone"))?;
+ println!("before: {:?}", rating(&before));
+ let tag = before.get("recordChangeTag").and_then(|t| t.as_str());
+ photos::set_rating(&http, &ck, p.clone(), &asset, tag, 3).await?;
+ let now = zc.lookup_record(ZONE, &asset).await?.unwrap();
+ println!("set: {:?}", rating(&now));
+ let tag = now.get("recordChangeTag").and_then(|t| t.as_str());
+ photos::set_rating(&http, &ck, p.clone(), &asset, tag, 0).await?;
+ let back = zc.lookup_record(ZONE, &asset).await?.unwrap();
+ println!("clear: {:?}", rating(&back));
+ Ok(())
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 5f262ed..0784f15 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -3769,6 +3769,7 @@ fn main() {
photos::photos_album_add,
photos::photos_album_remove,
photos::photo_set_text,
+ photos::photo_set_rating,
photos::photo_download,
note_table_add_row,
note_table_remove,
diff --git a/src-tauri/src/photos.rs b/src-tauri/src/photos.rs
index 111e607..37e0c60 100644
--- a/src-tauri/src/photos.rs
+++ b/src-tauri/src/photos.rs
@@ -502,6 +502,50 @@ pub async fn photo_set_text(
Ok(photo)
}
+/// A photo's star rating, 0 to 5, as set in its Info: Apple's answer taken at once.
+#[tauri::command]
+pub async fn photo_set_rating(
+ id: String,
+ rating: i64,
+ auth: State<'_, Auth>,
+ data: State<'_, Data>,
+) -> UiResult<Photo> {
+ if !(0..=5).contains(&rating) {
+ return Err("A rating is from none to five stars.".into());
+ }
+ let _one = crate::PHOTOS_PASS.lock().await;
+ let mut photo = data
+ .0
+ .lock()
+ .await
+ .photo(&id)
+ .map_err(|e| e.to_string())?
+ .ok_or("That photo is no longer in the library.")?;
+ let (http, root, params) = crate::cloudkit_context(&auth).await?;
+ let answer = quince_icloud::photos::set_rating(
+ &http,
+ &root,
+ params,
+ &id,
+ photo.change_tag.as_deref(),
+ rating,
+ )
+ .await
+ .map_err(|e| e.to_string())?;
+ photo.rating = rating;
+ photo.change_tag = answer
+ .get("recordChangeTag")
+ .and_then(serde_json::Value::as_str)
+ .map(str::to_string)
+ .or(photo.change_tag);
+ data.0
+ .lock()
+ .await
+ .put_photos(std::slice::from_ref(&photo))
+ .map_err(|e| e.to_string())?;
+ Ok(photo)
+}
+
/// A video opened in this computer's own player. WebKitGTK plays nothing without GStreamer's
/// codec plugins, which many systems (his among them) do not have, so a video is fetched once,
/// kept beside the other pictures under its own name, and handed to the system's player.
diff --git a/src/lib/ipc.ts b/src/lib/ipc.ts
index e0b7823..a18338b 100644
--- a/src/lib/ipc.ts
+++ b/src/lib/ipc.ts
@@ -101,6 +101,7 @@ export const api = {
photoDownload: (id: string) => invoke<string>("photo_download", { id }),
/** Title and caption together, as Info saves them. */
photoSetText: (id: string, title: string, caption: string) => invoke<Photo>("photo_set_text", { id, title, caption }),
+ photoSetRating: (id: string, rating: number) => invoke<Photo>("photo_set_rating", { id, rating }),
/** Photos and videos (or folders of them) into the library. Answers the batch; progress
* arrives as PHOTO_UPLOAD events, in the same shape as Drive's. */
/** Into the library, and into `album` too when one is open. */
@@ -562,7 +563,7 @@ export function pictureSrc(id: string, size: "thumb" | "medium" | "full" | "orig
export type PhotoAlbum = { id: string; name: string; position: number; changeTag: string | null };
-export type PhotoView = "library" | "favorites" | "videos" | "screenshots" | "recents" | "hidden" | "recentlyDeleted";
+export type PhotoView = "library" | "favorites" | "videos" | "screenshots" | "recents" | "hidden" | "rated" | "recentlyDeleted";
export type Photo = {
id: string;
@@ -586,6 +587,8 @@ export type Photo = {
/** Its title and caption, as typed in Photos' Info. */
title?: string | null;
caption?: string | null;
+ /** Its star rating, 0 (none) to 5. */
+ rating?: number;
subtype: number;
changeTag: string | null;
};
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index fd58d41..e5ade31 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -7,7 +7,7 @@ import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useStat
import { listen } from "@tauri-apps/api/event";
import { getCurrentWebview } from "@tauri-apps/api/webview";
import { open as openFileDialog } from "@tauri-apps/plugin-dialog";
-import { ChevronLeft, ChevronRight, CopyMinus, CopyPlus, Download, Clock, Heart, ImagePlus, Images, Info, Minus, Play, Plus, RotateCcw, Scan, Trash2, EyeOff, ArrowDownUp, MonitorPlay, Square, RectangleHorizontal, Video, X, type LucideIcon } from "lucide-react";
+import { ChevronLeft, ChevronRight, CopyMinus, CopyPlus, Download, Clock, Heart, ImagePlus, Images, Info, Minus, Play, Plus, RotateCcw, Scan, Trash2, EyeOff, ArrowDownUp, MonitorPlay, Square, RectangleHorizontal, Star, Video, X, type LucideIcon } from "lucide-react";
import {
api,
messageOf,
@@ -37,6 +37,7 @@ const MEDIA: typeof VIEWS = [
];
/** Photos' Utilities: what is kept out of the library. */
const UTILITIES: typeof VIEWS = [
+ { key: "rated", label: "Rated", Icon: Star },
{ key: "hidden", label: "Hidden", Icon: EyeOff },
{ key: "recentlyDeleted", label: "Recently Deleted", Icon: Trash2 },
];
@@ -175,6 +176,7 @@ const Tile = memo(function Tile({
</span>
)}
{left && <span className={`px-badge px-left${soon ? " is-soon" : ""}`}>{left}</span>}
+ {(photo.rating ?? 0) > 0 && <span className="px-stars" aria-label={`${photo.rating} stars`}>{photo.rating}★</span>}
{photo.favorite && <Heart className="px-heart" size={13} strokeWidth={0} fill="currentColor" aria-label="Favorite" />}
</span>
</button>
@@ -297,7 +299,7 @@ export function PhotosView() {
// Each view keeps the sort chosen for it, on this machine. Albums keep their own order, and
// Recently Deleted its own, as in Photos.
const [sorts, setSorts] = useState(readSorts);
- const sortable = !album && view !== "recentlyDeleted";
+ const sortable = !album && view !== "recentlyDeleted" && view !== "rated";
const sort = sortable ? (sorts[view] ?? defaultSort(view)) : null;
const chooseSort = (next: Sort) => {
setSorts((all) => {
@@ -344,13 +346,15 @@ export function PhotosView() {
const out: { label: string; items: { photo: Photo; index: number }[] }[] = [];
if (album) return [{ label: "", items: (photos ?? []).map((photo, index) => ({ photo, index })) }];
(photos ?? []).forEach((photo, index) => {
- const label = monthOf(sortKey(photo, sort?.by ?? "taken"));
+ // Rated is grouped by how many stars, as icloud.com's Rated page is.
+ const stars = photo.rating ?? 0;
+ const label = view === "rated" ? `${stars} ${stars === 1 ? "Star" : "Stars"}` : monthOf(sortKey(photo, sort?.by ?? "taken"));
const last = out[out.length - 1];
if (last && last.label === label) last.items.push({ photo, index });
else out.push({ label, items: [{ photo, index }] });
});
return out;
- }, [photos, sort?.by, album]);
+ }, [photos, sort?.by, album, view]);
const shown = open !== null ? photos?.[open] ?? null : null;
@@ -1076,6 +1080,21 @@ export function PhotosView() {
if (e.currentTarget.contains(e.relatedTarget as Node | null)) return;
void words(p, titleField.current?.value ?? p.title ?? "", captionField.current?.value ?? p.caption ?? "");
};
+ const rate = async (p: Photo, rating: number) => {
+ const before = photos;
+ const leaves = view === "rated" && rating === 0;
+ setPhotos((all) =>
+ leaves ? (all ?? []).filter((x) => x.id !== p.id) : (all ?? []).map((x) => (x.id === p.id ? { ...x, rating } : x)),
+ );
+ try {
+ await api.photoSetRating(p.id, rating);
+ read().catch(() => {});
+ } catch (e) {
+ setPhotos(before);
+ setError(messageOf(e));
+ }
+ };
+
const words = async (p: Photo, title: string, caption: string) => {
const [t, c] = [title.trim(), caption.trim()];
if (t === (p.title ?? "") && c === (p.caption ?? "")) return;
@@ -1608,6 +1627,23 @@ export function PhotosView() {
onKeyDown={(e) => wordKeys(e, shown.caption)}
/>
</dd>
+ {/* Stars, as Info sets them: a click gives that many; the same again takes them away. */}
+ <dt>Rating</dt>
+ <dd className="px-rating" role="radiogroup" aria-label="Rating">
+ {[1, 2, 3, 4, 5].map((n) => (
+ <button
+ key={n}
+ role="radio"
+ aria-checked={(shown.rating ?? 0) === n}
+ aria-label={`${n} ${n === 1 ? "star" : "stars"}`}
+ className={`px-star${(shown.rating ?? 0) >= n ? " is-on" : ""}`}
+ disabled={view === "recentlyDeleted"}
+ onClick={() => void rate(shown, (shown.rating ?? 0) === n ? 0 : n)}
+ >
+ <Star size={15} fill={(shown.rating ?? 0) >= n ? "currentColor" : "none"} strokeWidth={1.8} />
+ </button>
+ ))}
+ </dd>
<dt>Name</dt>
<dd>{shown.filename ?? "—"}</dd>
<dt>Taken</dt>
diff --git a/src/styles/photos.css b/src/styles/photos.css
index 298b1a4..ba6ff3d 100644
--- a/src/styles/photos.css
+++ b/src/styles/photos.css
@@ -473,3 +473,37 @@
.px-title-field:hover:not(:read-only), .px-caption:hover:not(:read-only) { background: color-mix(in srgb, var(--text) 6%, transparent); }
.px-title-field:focus, .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; }
+
+/* A rated photo's stars on its tile, as icloud.com marks them: a small dark chip, top left. */
+.px-stars {
+ position: absolute;
+ top: 6px;
+ left: 6px;
+ padding: 1px 5px;
+ border-radius: 5px;
+ background: rgba(0, 0, 0, 0.55);
+ color: #fff;
+ font-size: 10px;
+ font-weight: 600;
+ line-height: 15px;
+ font-variant-numeric: tabular-nums;
+}
+/* Info's stars. */
+.px-rating { display: flex; gap: 2px; margin: 4px 0 0 -4px; }
+.px-star {
+ display: grid;
+ place-items: center;
+ width: 26px;
+ height: 26px;
+ padding: 0;
+ border: 0;
+ border-radius: 6px;
+ background: transparent;
+ color: var(--text-3);
+ cursor: default;
+ transition: color 120ms ease, transform 140ms var(--spring-quick);
+}
+.px-star.is-on { color: #ff9f0a; }
+.px-star:hover:not(:disabled) { background: color-mix(in srgb, var(--text) 7%, transparent); }
+.px-star:active:not(:disabled) { transform: scale(0.88); }
+.px-star:focus-visible { outline: 2px solid var(--accent-ring); outline-offset: -2px; }