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 sidebar as icloud.com's — Collections, with Albums and Media Types opening

Yashwanth Kamireddi88e92efd7a99
diff --git a/crates/quince-core/src/photos.rs b/crates/quince-core/src/photos.rs
index f608a68..5abbc70 100644
--- a/crates/quince-core/src/photos.rs
+++ b/crates/quince-core/src/photos.rs
@@ -443,13 +443,17 @@ impl Library {
Ok(())
}
- /// Every album with how many photos it shows (deleted and hidden ones not counted), in
- /// the order the albums are listed.
- pub fn albums_counted(&self) -> Result<Vec<(Album, i64)>> {
+ /// Every album with how many photos it shows (deleted and hidden ones not counted) and
+ /// the first of them — its cover, as the sidebar and the albums page show it — in the
+ /// order the albums are listed.
+ pub fn albums_counted(&self) -> Result<Vec<(Album, i64, Option<String>)>> {
let mut stmt = self.conn.prepare(
"SELECT a.id, a.name, a.position, a.change_tag,
(SELECT COUNT(*) FROM photo_album_items i JOIN photos p ON p.id = i.asset
- WHERE i.album = a.id AND p.deleted = 0 AND p.hidden = 0)
+ WHERE i.album = a.id AND p.deleted = 0 AND p.hidden = 0),
+ (SELECT i.asset FROM photo_album_items i JOIN photos p ON p.id = i.asset
+ WHERE i.album = a.id AND p.deleted = 0 AND p.hidden = 0
+ ORDER BY i.position, p.taken_at DESC, p.id LIMIT 1)
FROM photo_albums a ORDER BY a.position, a.name",
)?;
let rows = stmt.query_map([], |r| {
@@ -461,6 +465,7 @@ impl Library {
change_tag: r.get(3)?,
},
r.get(4)?,
+ r.get(5)?,
))
})?;
Ok(rows.collect::<std::result::Result<_, _>>()?)
@@ -586,6 +591,11 @@ mod tests {
2,
"an album's count is what it shows"
);
+ assert_eq!(
+ lib.albums_counted().unwrap()[0].2.as_deref(),
+ Some("a"),
+ "and its cover is the first it shows"
+ );
lib.forget_album_items(&[("AL".into(), "a".into())])
.unwrap();
assert_eq!(lib.album_photos("AL").unwrap().len(), 1);
diff --git a/src-tauri/src/photos.rs b/src-tauri/src/photos.rs
index 37e0c60..58adef0 100644
--- a/src-tauri/src/photos.rs
+++ b/src-tauri/src/photos.rs
@@ -189,7 +189,7 @@ pub async fn photos_list(view: View, data: State<'_, Data>) -> UiResult<Vec<Phot
#[tauri::command]
pub async fn photos_albums(
data: State<'_, Data>,
-) -> UiResult<Vec<(quince_core::photos::Album, usize)>> {
+) -> UiResult<Vec<(quince_core::photos::Album, usize, Option<String>)>> {
let counted = data
.0
.lock()
@@ -198,7 +198,7 @@ pub async fn photos_albums(
.map_err(|e| e.to_string())?;
Ok(counted
.into_iter()
- .map(|(a, n)| (a, usize::try_from(n).unwrap_or(0)))
+ .map(|(a, n, cover)| (a, usize::try_from(n).unwrap_or(0), cover))
.collect())
}
diff --git a/src/lib/ipc.ts b/src/lib/ipc.ts
index a18338b..4ebc0a5 100644
--- a/src/lib/ipc.ts
+++ b/src/lib/ipc.ts
@@ -90,7 +90,8 @@ export const api = {
photosList: (view: PhotoView) => invoke<Photo[]>("photos_list", { view }),
photosCounts: () => invoke<[PhotoView, number][]>("photos_counts"),
/** The albums the person made, each with how many photos it holds. */
- photosAlbums: () => invoke<[PhotoAlbum, number][]>("photos_albums"),
+ /** Each album, how many it shows, and its cover — the first photo it shows. */
+ photosAlbums: () => invoke<[PhotoAlbum, number, string | null][]>("photos_albums"),
photosInAlbum: (album: string) => invoke<Photo[]>("photos_in_album", { album }),
/** A video (or a Live Photo's moving part) opened in this computer's own player. */
photoPlay: (id: string) => invoke<void>("photo_play", { id }),
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index e5ade31..0ff10d5 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, Star, 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, Layers, Video, X, type LucideIcon } from "lucide-react";
import {
api,
messageOf,
@@ -258,7 +258,25 @@ export function PhotosView() {
const [view, setView] = useState<PhotoView>("library");
/** An album open instead of a view. */
const [album, setAlbum] = useState<PhotoAlbum | null>(null);
- const [albums, setAlbums] = useState<[PhotoAlbum, number][]>([]);
+ const [albums, setAlbums] = useState<[PhotoAlbum, number, (string | null)?][]>([]);
+ // Which of the sidebar's branches are open — Albums and Media Types — kept on this machine.
+ const [branches, setBranches] = useState<{ albums: boolean; media: boolean }>(() => {
+ try {
+ return { albums: true, media: true, ...JSON.parse(window.localStorage.getItem("quince.photos.branches") ?? "{}") };
+ } catch {
+ return { albums: true, media: true };
+ }
+ });
+ const branch = (which: "albums" | "media") =>
+ setBranches((b) => {
+ const next = { ...b, [which]: !b[which] };
+ try {
+ window.localStorage.setItem("quince.photos.branches", JSON.stringify(next));
+ } catch {
+ // For this run only.
+ }
+ return next;
+ });
/** 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>>>({});
@@ -1292,52 +1310,75 @@ export function PhotosView() {
<aside className="px-side" aria-label="Photos">
<p className="px-side-heading">Photos</p>
{VIEWS.map(source)}
- <p className="px-side-heading px-side-gap">Media Types</p>
- {MEDIA.map(source)}
- <div className="px-side-row">
- <p className="px-side-heading">Albums</p>
- <button className="px-side-add" aria-label="New Album" title="New Album" onClick={() => setNaming({ id: null, then: [], draft: "" })}>
+ {/* Collections, as icloud.com lists them: Albums and Media Types open to what they
+ hold, then Rated, Hidden and Recently Deleted. */}
+ <p className="px-side-heading px-side-gap">Collections</p>
+ <div className="px-parent-row">
+ <button className="px-source px-parent" aria-expanded={branches.albums} onClick={() => branch("albums")}>
+ <ChevronRight className="px-chevron" size={12} strokeWidth={2.4} aria-hidden="true" />
+ <AlbumGlyph />
+ <span className="px-label">Albums</span>
+ </button>
+ <button className="px-side-add" aria-label="New Album" title="New Album" onClick={() => {
+ if (!branches.albums) branch("albums");
+ setNaming({ id: null, then: [], draft: "" });
+ }}>
<Plus size={14} strokeWidth={2} aria-hidden="true" />
</button>
</div>
- <div className="px-albums" role="group" aria-label="Albums">
- {naming?.id === null && nameField}
- {albums.map(([a, n]) =>
- naming?.id === a.id ? (
- <span key={a.id}>{nameField}</span>
- ) : (
- <button
- key={a.id}
- className="px-source"
- aria-current={album?.id === a.id}
- onClick={() => {
- setAlbum(a);
- setOpen(null);
- }}
- onDoubleClick={() => setNaming({ id: a.id, then: [], draft: a.name })}
- {...dropTarget(a)}
- data-drop={dropOn === a.id || undefined}
- onContextMenu={(e) => {
- e.preventDefault();
- if (a.id.startsWith("new:")) return;
- setMenu({
- at: { x: e.clientX, y: e.clientY, alignRight: false },
- entries: [
- { label: "Rename Album", run: () => setNaming({ id: a.id, then: [], draft: a.name }) },
- null,
- { label: "Delete Album", danger: true, run: () => void deleteAlbum(a) },
- ],
- });
- }}
- >
- <AlbumGlyph />
- <span className="px-label">{a.name}</span>
- {n ? <span className="px-count">{n}</span> : null}
- </button>
- ),
+ {branches.albums && (
+ <div className="px-albums px-children" role="group" aria-label="Albums">
+ {naming?.id === null && nameField}
+ {albums.map(([a, n, cover]) =>
+ naming?.id === a.id ? (
+ <span key={a.id}>{nameField}</span>
+ ) : (
+ <button
+ key={a.id}
+ className="px-source"
+ aria-current={album?.id === a.id}
+ onClick={() => {
+ setAlbum(a);
+ setOpen(null);
+ }}
+ onDoubleClick={() => setNaming({ id: a.id, then: [], draft: a.name })}
+ {...dropTarget(a)}
+ data-drop={dropOn === a.id || undefined}
+ onContextMenu={(e) => {
+ e.preventDefault();
+ if (a.id.startsWith("new:")) return;
+ setMenu({
+ at: { x: e.clientX, y: e.clientY, alignRight: false },
+ entries: [
+ { label: "Rename Album", run: () => setNaming({ id: a.id, then: [], draft: a.name }) },
+ null,
+ { label: "Delete Album", danger: true, run: () => void deleteAlbum(a) },
+ ],
+ });
+ }}
+ >
+ {cover ? (
+ <img className="px-cover" src={pictureSrc(cover, "thumb")} alt="" loading="lazy" decoding="async" draggable={false} />
+ ) : (
+ <AlbumGlyph />
+ )}
+ <span className="px-label">{a.name}</span>
+ {n ? <span className="px-count">{n}</span> : null}
+ </button>
+ ),
+ )}
+ </div>
+ )}
+ <button className="px-source px-parent" aria-expanded={branches.media} onClick={() => branch("media")}>
+ <ChevronRight className="px-chevron" size={12} strokeWidth={2.4} aria-hidden="true" />
+ <Layers size={16} strokeWidth={1.8} className="px-glyph" aria-hidden="true" />
+ <span className="px-label">Media Types</span>
+ </button>
+ {branches.media && (
+ <div className="px-children" role="group" aria-label="Media Types">
+ {MEDIA.map(source)}
+ </div>
)}
- </div>
- <p className="px-side-heading px-side-gap">Utilities</p>
{UTILITIES.map(source)}
</aside>
diff --git a/src/styles/photos.css b/src/styles/photos.css
index ba6ff3d..e28241f 100644
--- a/src/styles/photos.css
+++ b/src/styles/photos.css
@@ -507,3 +507,15 @@
.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; }
+
+/* ---- the sidebar's branches: Albums and Media Types open to what they hold ---------------- */
+.px-parent-row { position: relative; display: flex; align-items: center; }
+.px-parent-row .px-parent { flex: 1; min-width: 0; }
+.px-parent-row .px-side-add { position: absolute; right: 6px; }
+.px-parent { padding-left: 2px; }
+.px-chevron { flex: none; color: var(--text-3); transition: transform 180ms var(--spring-quick); }
+.px-parent[aria-expanded="true"] .px-chevron { transform: rotate(90deg); }
+.px-children { display: flex; flex-direction: column; gap: 1px; }
+.px-children .px-source, .px-children .px-naming { padding-left: 30px; }
+/* An album's cover in the sidebar, where a symbol stands for the others. */
+.px-cover { flex: none; width: 18px; height: 18px; border-radius: 4px; object-fit: cover; box-shadow: 0 0 0 0.5px color-mix(in srgb, var(--text) 18%, transparent); }