diff --git a/apps/mobile/src/apps/Media.tsx b/apps/mobile/src/apps/Media.tsx index 3a5d572d..a0de26b0 100644 --- a/apps/mobile/src/apps/Media.tsx +++ b/apps/mobile/src/apps/Media.tsx @@ -14,9 +14,10 @@ import { useBack } from "../shell/back"; import { onOpen } from "../shell/nav"; import { persisted } from "../store"; import { Banner, Block, Button, catColor, confirm, Empty, FieldRow, FIXED, Header, Hint, Icon, ListRow, makeStyles, num, RADIUS, Screen, SectionLabel, Seg, Sheet, toast, type, useRefreshControl, useTheme } from "../ui"; -import { authHeaders, canvasImageUrl } from "../api"; +import { authHeaders, canvasImageUrl, imageUrl } from "../api"; import { CanvasPage, CanvasWeb } from "./CanvasView"; import { PhotoProperties } from "./PhotoProperties"; +import { FullPhoto, SwipePhoto } from "./PhotoViewer"; import { registerApp } from "./registry"; /** @@ -24,12 +25,13 @@ import { registerApp } from "./registry"; * the photos at the top level below them. Collections as stacks in their colour, or spread out with * each photo carrying its collection's mark (the account's preference, as in the Studio). A badge on * what is still uploading or stuck. Import from the phone runs through the camera's pipeline; the - * tick chooses photos to make a collection. + * long-press on a photo starts choosing photos to make a collection. */ const view = persisted<"photos" | "folders">("mediaView.v1", "photos"); const spreadOut = persisted("mediaSpread.v1", false); -type Open = { kind: "photo" | "collection" | "folder" | "canvas" | "edit"; id: string }; +/** A photo is opened with the list the grid showed, in its order, to step through (#557). */ +type Open = { kind: "photo" | "collection" | "folder" | "canvas" | "edit"; id: string; list?: string[] }; function Media({ active }: { active: boolean }) { const project = useProject(); @@ -54,7 +56,10 @@ function Media({ active }: { active: boolean }) { } if (top?.kind === "photo") { const p = lib.photos.find((x) => x.id === top.id); - if (p) return ; + // Opened without a list (a link from elsewhere): its collection's photos, else its folder's, newest first. + const list = (top.list ?? lib.photos.filter((x) => x.container === p?.container).reverse().map((x) => x.id)).filter((id) => lib.photos.some((x) => x.id === id)); + const go = (id: string) => setStack((st) => [...st.slice(0, -1), { ...top, id, list }]); + if (p) return ; } const holder = top && (top.kind === "folder" || top.kind === "collection") ? lib.holders.find((h) => h.id === top.id) ?? null : null; return ; @@ -90,31 +95,37 @@ function Browser({ holder, lib, canvases, picked, setPicked, open, back }: { hol toast(failed.length ? `${added} imported; ${failed.length} could not be read` : `${added} imported`, failed.length ? "danger" : "ok"); } catch (e) { log("warn", "import picker failed", e); toast("The pictures could not be imported", "danger"); } }; + // The server names it from the project's pattern (#548): unique, whatever was renamed or deleted. const make = async () => { if (!picked?.length) return; - const n = colls.length + 1; - try { await makeCollection(picked, `Collection ${n}`, holder?.type === "folder" ? holder.id : null); setPicked(null); toast(`Collection ${n} made`); } + try { const name = await makeCollection(picked, holder?.type === "folder" ? holder.id : null); setPicked(null); toast(`${name} made`); } catch (e) { toast(`No collection: ${(e as Error).message}`, "danger"); } }; const title = picked ? `${picked.length} chosen` : holder?.name ?? "Media"; const sub = picked ? "Tap photos to choose them" : holder ? (inColl ? `Collection · ${photos.length} photos` : "Folder") : project?.name; + const stackSwitch = spreadOut.set(v === "spread")} accessibilityLabel="Collections stacked or spread out" />; return ( setPicked(null) : back} - actions={picked ? [] : [!inColl && { icon: spread ? "layers" : "grid", label: spread ? "Collections as stacks" : "Collections spread out", onPress: () => spreadOut.set(!spread) }, { icon: "download", label: "Import from the phone", onPress: () => void importPictures() }, { icon: "check", label: "Choose several", onPress: () => setPicked([]) }]} />} + actions={picked ? [] : [{ icon: "upload", label: "Import from the phone", onPress: () => void importPictures() }]} />} footer={picked ? <>