From ba1142c73f418e65d37918c89fe0558e3213620a Mon Sep 17 00:00:00 2001 From: spark Date: Fri, 6 Nov 2026 21:42:59 +0000 Subject: [PATCH] feat(library): filter photos with no colour and add selection menus The colour bar had no way to show only unmarked photos, and the system menu cannot select or mark them. --- apps/app/src/i18n.ts | 9 ++ apps/app/src/library/FilterBar.tsx | 10 +- apps/app/src/library/LibraryMenus.tsx | 146 ++++++++++++++++++++++++++ apps/app/src/library/active.ts | 5 +- apps/app/src/library/store.test.ts | 9 +- apps/app/src/library/store.ts | 25 +++-- apps/app/src/pages/LibraryPage.tsx | 19 ++++ 7 files changed, 210 insertions(+), 13 deletions(-) create mode 100644 apps/app/src/library/LibraryMenus.tsx diff --git a/apps/app/src/i18n.ts b/apps/app/src/i18n.ts index e46e284..6d8f73b 100644 --- a/apps/app/src/i18n.ts +++ b/apps/app/src/i18n.ts @@ -103,6 +103,15 @@ export const t = { markColor: "Marcar", colorOnly: (name: string) => `Só ${name.toLowerCase()}`, colorWithout: (name: string) => `Sem ${name.toLowerCase()}`, + colorUncolored: "Só sem cor", + colorNone: "Sem cor", + menuSelection: "Seleção", + menuSelectAll: "Selecionar todas", + menuSelectNone: "Limpar seleção", + menuSelectUncolored: "Selecionar sem cor", + menuImage: "Imagem", + menuSetColor: "Definir cor", + menuSetRating: "Definir estrelas", colors: { RED: "Vermelho", YELLOW: "Amarelo", GREEN: "Verde", BLUE: "Azul", PURPLE: "Roxo" }, deliveryFilter: "Envio:", deliveryStates: { any: "Todas", unsent: "Por enviar", queued: "A enviar", sent: "Enviadas", failed: "Com erro" }, diff --git a/apps/app/src/library/FilterBar.tsx b/apps/app/src/library/FilterBar.tsx index c50d958..f78d799 100644 --- a/apps/app/src/library/FilterBar.tsx +++ b/apps/app/src/library/FilterBar.tsx @@ -1,7 +1,7 @@ import type { ColorLabel } from "@photoreport/contracts"; import { t } from "../i18n.js"; import { LABEL_COLOR } from "./Grid.js"; -import { ALL_PHOTOS, cycleColor, isAll, type LibraryFilter } from "./store.js"; +import { ALL_PHOTOS, cycleColor, isAll, onlyUncolored, type LibraryFilter } from "./store.js"; const FLAGS: LibraryFilter["flag"][] = ["all", "PICK", "UNFLAGGED", "UNREJECTED", "REJECT"]; const DELIVERY: LibraryFilter["delivery"][] = ["any", "unsent", "queued", "sent", "failed"]; @@ -57,6 +57,14 @@ export function FilterBar(props: { filter: LibraryFilter; onChange: (f: LibraryF ); })} + + ))} + + run(() => props.onFlag("PICK"))} /> + run(() => props.onFlag("REJECT"))} /> + run(() => props.onFlag("NONE"))} /> + run(props.onInfo)} /> + {props.canRemove && ( + run(props.onRemove)} /> + )} + + )} + + + ); +} + +function MenuButton(props: { label: string; pressed: boolean; onClick: () => void; children: ReactNode }) { + return ( +
+ + {props.children} +
+ ); +} + +function MenuPanel(props: { children: ReactNode }) { + return ( +
+ {props.children} +
+ ); +} + +function Item(props: { label: string; disabled?: boolean; danger?: boolean; swatch?: string; onSelect: () => void }) { + return ( + + ); +} diff --git a/apps/app/src/library/active.ts b/apps/app/src/library/active.ts index 85e5e22..b928670 100644 --- a/apps/app/src/library/active.ts +++ b/apps/app/src/library/active.ts @@ -53,8 +53,9 @@ export function savedFilter(orgId: string): LibraryFilter { return { flag: FLAGS.includes(v.flag as string) ? v.flag! : "all", minRating: Number.isInteger(v.minRating) && v.minRating! >= 0 && v.minRating! <= 5 ? v.minRating! : 0, - color: COLORS.includes(v.color as string) ? v.color! : null, - withoutColor: v.withoutColor === true && COLORS.includes(v.color as string), + color: v.uncolored === true || !COLORS.includes(v.color as string) ? null : v.color!, + withoutColor: v.uncolored !== true && v.withoutColor === true && COLORS.includes(v.color as string), + uncolored: v.uncolored === true, delivery: DELIVERY.includes(v.delivery as string) ? v.delivery! : "any", noPlayers: v.noPlayers === true, }; diff --git a/apps/app/src/library/store.test.ts b/apps/app/src/library/store.test.ts index ba77c67..28b1958 100644 --- a/apps/app/src/library/store.test.ts +++ b/apps/app/src/library/store.test.ts @@ -1,6 +1,6 @@ import type { PhotoSummary } from "@photoreport/contracts"; import { describe, expect, it } from "vitest"; -import { ALL_PHOTOS, cycleColor, initialLibrary, type LibraryFilter, libraryReducer, matchesFilter, patchForKey } from "./store.js"; +import { ALL_PHOTOS, cycleColor, initialLibrary, type LibraryFilter, libraryReducer, matchesFilter, onlyUncolored, patchForKey } from "./store.js"; const photo = (id: string, capturedAt: string, extra: Partial = {}): PhotoSummary => ({ id, @@ -80,7 +80,12 @@ describe("library store", () => { expect(matchesFilter(photo("a", "", { colorLabel: "RED" }), hideRed)).toBe(false); expect(matchesFilter(photo("a", "", { colorLabel: "NONE" }), hideRed)).toBe(true); expect(matchesFilter(photo("a", "", { colorLabel: "GREEN" }), hideRed)).toBe(true); - expect(cycleColor(hideRed, "RED")).toEqual({ color: null, withoutColor: false }); + expect(cycleColor(hideRed, "RED")).toEqual({ color: null, withoutColor: false, uncolored: false }); + const bare = onlyUncolored(ALL_PHOTOS); + expect(bare).toEqual({ color: null, withoutColor: false, uncolored: true }); + expect(matchesFilter(photo("a", "", { colorLabel: "NONE" }), { ...ALL_PHOTOS, ...bare })).toBe(true); + expect(matchesFilter(photo("a", "", { colorLabel: "RED" }), { ...ALL_PHOTOS, ...bare })).toBe(false); + expect(onlyUncolored({ ...ALL_PHOTOS, ...bare })).toEqual({ color: null, withoutColor: false, uncolored: false }); expect(matchesFilter(photo("a", "", { delivery: "FAILED" }), { ...ALL_PHOTOS, delivery: "failed" })).toBe(true); }); diff --git a/apps/app/src/library/store.ts b/apps/app/src/library/store.ts index 44027e7..ccd6d21 100644 --- a/apps/app/src/library/store.ts +++ b/apps/app/src/library/store.ts @@ -221,21 +221,29 @@ export interface LibraryFilter { color: ColorLabel | null; /** When set with `color`, hide photos that wear it and keep the rest. */ withoutColor: boolean; + /** Photo Mechanic's dotted chip: only photos with no colour class. */ + uncolored: boolean; delivery: "any" | "unsent" | "queued" | "sent" | "failed"; noPlayers: boolean; } -export const ALL_PHOTOS: LibraryFilter = { flag: "all", minRating: 0, color: null, withoutColor: false, delivery: "any", noPlayers: false }; +export const ALL_PHOTOS: LibraryFilter = { flag: "all", minRating: 0, color: null, withoutColor: false, uncolored: false, delivery: "any", noPlayers: false }; export function isAll(f: LibraryFilter): boolean { - return f.flag === "all" && !f.minRating && !f.color && !f.withoutColor && f.delivery === "any" && !f.noPlayers; + return f.flag === "all" && !f.minRating && !f.color && !f.withoutColor && !f.uncolored && f.delivery === "any" && !f.noPlayers; } /** Colour chip: first click keeps that colour, second click hides it, third click clears. */ -export function cycleColor(f: LibraryFilter, color: ColorLabel): Pick { - if (f.color !== color) return { color, withoutColor: false }; - if (!f.withoutColor) return { color, withoutColor: true }; - return { color: null, withoutColor: false }; +export function cycleColor(f: LibraryFilter, color: ColorLabel): Pick { + if (f.uncolored || f.color !== color) return { color, withoutColor: false, uncolored: false }; + if (!f.withoutColor) return { color, withoutColor: true, uncolored: false }; + return { color: null, withoutColor: false, uncolored: false }; +} + +/** The dotted chip: only photos that have no colour, or back to every colour. */ +export function onlyUncolored(f: LibraryFilter): Pick { + if (f.uncolored) return { color: null, withoutColor: false, uncolored: false }; + return { color: null, withoutColor: false, uncolored: true }; } export function matchesFilter(photo: PhotoSummary, f: LibraryFilter): boolean { @@ -244,8 +252,9 @@ export function matchesFilter(photo: PhotoSummary, f: LibraryFilter): boolean { if (f.flag === "UNREJECTED" && photo.flag === "REJECT") return false; if (f.flag === "UNFLAGGED" && photo.flag !== "NONE") return false; if (f.minRating && photo.rating < f.minRating) return false; - if (f.color && f.withoutColor && photo.colorLabel === f.color) return false; - if (f.color && !f.withoutColor && photo.colorLabel !== f.color) return false; + if (f.uncolored && photo.colorLabel !== "NONE") return false; + if (!f.uncolored && f.color && f.withoutColor && photo.colorLabel === f.color) return false; + if (!f.uncolored && f.color && !f.withoutColor && photo.colorLabel !== f.color) return false; const d = photo.delivery ?? "NONE"; if (f.delivery === "unsent" && d !== "NONE") return false; if (f.delivery === "queued" && d !== "QUEUED") return false; diff --git a/apps/app/src/pages/LibraryPage.tsx b/apps/app/src/pages/LibraryPage.tsx index 740b9ee..480c869 100644 --- a/apps/app/src/pages/LibraryPage.tsx +++ b/apps/app/src/pages/LibraryPage.tsx @@ -40,6 +40,7 @@ import { isNetworkError, offlineQueue } from "../offline/queue.js"; import { ensureRoster } from "../offline/roster.js"; import { patchPhotos, useQueueSize } from "../offline/sync.js"; import { FilterBar } from "../library/FilterBar.js"; +import { LibraryMenus } from "../library/LibraryMenus.js"; import { SendButton } from "../library/SendButton.js"; import { isDesktop, prefs } from "../platform.js"; import { activePhoto, savedFilter, saveFilter, setActivePhoto } from "../library/active.js"; @@ -545,6 +546,24 @@ export function LibraryPage() {
+ {!sheet && ( + 0} + canRemove={isEventScope(state.scope)} + onSelectAll={() => dispatch({ type: "selectAll", visible: visibleIds })} + onSelectNone={() => dispatch({ type: "selectAll", visible: [] })} + onSelectUncolored={() => { + const ids = visible.filter((p) => p.colorLabel === "NONE").map((p) => p.id); + dispatch({ type: "selectMany", ids, focus: ids[0] ?? null }); + }} + onColor={(color) => void patch(selection.map((p) => p.id), { colorLabel: color })} + onRating={(rating) => void patch(selection.map((p) => p.id), { rating })} + onFlag={(flag) => void patch(selection.map((p) => p.id), { flag })} + onInfo={() => setIptcOpen(true)} + onRemove={() => setRemoveOpen(true)} + /> + )} {players.length > 0 && ( -- 2.47.3