From a9b19ebde76e2fefe6d6077db7618866c1bd810b Mon Sep 17 00:00:00 2001 From: zurdi Date: Thu, 21 May 2026 14:31:30 +0000 Subject: [PATCH] refactor: remove MetadataSections component and update gallery sorting logic - Deleted the MetadataSections.vue component, which handled metadata display for various providers. - Updated AlphaStrip.vue to include a direction prop for sorting letters in ascending or descending order. - Enhanced GalleryShell.vue to manage grid sorting direction and integrate it with the toolbar. - Modified GalleryToolbar.vue to add sorting direction controls for grid mode. - Adjusted PlatformTile.vue to simplify the playable indicator display. - Refactored useGalleryVirtualItems to normalize letter sorting with new bucket logic. - Added subtitle support to RTextField for enhanced context display. - Updated CollectionsIndex.vue to implement grid sorting functionality. - Refined PlatformsIndex.vue to separate list and grid sorting states, improving overall sorting logic. --- backend/endpoints/roms/__init__.py | 2 +- backend/handler/database/roms_handler.py | 12 +- .../v2/components/Dialogs/EditRomDialog.vue | 616 ++++++------------ .../components/EditRom/MetadataSections.vue | 120 ---- .../src/v2/components/Gallery/AlphaStrip.vue | 18 +- .../v2/components/Gallery/GalleryShell.vue | 18 + .../v2/components/Gallery/GalleryToolbar.vue | 50 ++ .../v2/components/Platforms/PlatformTile.vue | 11 +- .../useGalleryVirtualItems/index.ts | 8 +- .../forms/RTextField/RTextField.stories.ts | 25 + .../v2/lib/forms/RTextField/RTextField.vue | 68 +- frontend/src/v2/views/CollectionsIndex.vue | 46 +- frontend/src/v2/views/PlatformsIndex.vue | 145 +++-- 13 files changed, 533 insertions(+), 606 deletions(-) delete mode 100644 frontend/src/v2/components/EditRom/MetadataSections.vue diff --git a/backend/endpoints/roms/__init__.py b/backend/endpoints/roms/__init__.py index ea2c7ac79..2a4f668a5 100644 --- a/backend/endpoints/roms/__init__.py +++ b/backend/endpoints/roms/__init__.py @@ -535,7 +535,7 @@ def get_roms( char_index_dict = {} if with_char_index: char_index = db_rom_handler.with_char_index( - query=query, order_by_attr=order_by_attr + query=query, order_by_attr=order_by_attr, order_dir=order_dir.lower() ) char_index_dict = {char: index for (char, index) in char_index} diff --git a/backend/handler/database/roms_handler.py b/backend/handler/database/roms_handler.py index 1e7e958f8..3b2de9368 100644 --- a/backend/handler/database/roms_handler.py +++ b/backend/handler/database/roms_handler.py @@ -880,6 +880,7 @@ class DBRomsHandler(DBBaseHandler): self, query: Query, order_by_attr: Any, + order_dir: str = "asc", session: Session = None, # type: ignore ) -> list[Row[tuple[str, int]]]: if isinstance(order_by_attr.type, (String, Text)): @@ -897,6 +898,15 @@ class DBRomsHandler(DBBaseHandler): r"(\d+)", r"00000000000\1" ).regexp_replace(r"0*(\d{12})", r"\1") + # Apply the same direction the main query uses so the position + # numbers we emit (and the per-letter min position downstream) + # match the actual order the client paginates over. Without this + # the frontend AlphaStrip would highlight the wrong letter when + # order_dir=desc. + order_window = ( + order_by_attr.desc() if order_dir.lower() == "desc" else order_by_attr.asc() + ) + # Get the row number and first letter for each item subquery = ( query.with_only_columns(Rom.id, Rom.name) # type: ignore @@ -906,7 +916,7 @@ class DBRomsHandler(DBBaseHandler): 1, 1, ).label("letter"), - func.row_number().over(order_by=order_by_attr).label("position"), + func.row_number().over(order_by=order_window).label("position"), ) .subquery() ) diff --git a/frontend/src/v2/components/Dialogs/EditRomDialog.vue b/frontend/src/v2/components/Dialogs/EditRomDialog.vue index 27356f904..20c801c6a 100644 --- a/frontend/src/v2/components/Dialogs/EditRomDialog.vue +++ b/frontend/src/v2/components/Dialogs/EditRomDialog.vue @@ -1,26 +1,34 @@ - - - - diff --git a/frontend/src/v2/components/Gallery/AlphaStrip.vue b/frontend/src/v2/components/Gallery/AlphaStrip.vue index 2667bc1d5..c4422f705 100644 --- a/frontend/src/v2/components/Gallery/AlphaStrip.vue +++ b/frontend/src/v2/components/Gallery/AlphaStrip.vue @@ -15,20 +15,34 @@ import { computed } from "vue"; defineOptions({ inheritAttrs: false }); -const ALPHABET = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""); +// Two non-alphabetic buckets bookend the alphabet: +// * `#` — digits (0-9) — sits BEFORE A +// * `@` — any other non-alphanumeric first character — sits AFTER Z +// Order in asc: `# A B … Z @` — `#` at the top, `@` at the bottom. +// When the gallery sorts desc the whole array reverses (`@` to the top, +// `#` to the bottom) so the strip's visual order tracks the data's +// order and the scroll-spy highlight follows the scroll direction. +const ALPHABET = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ@".split(""); interface Props { available?: Set | string[]; current?: string; visible?: Set | string[]; + /** Render order — reversed when the gallery sorts descending. */ + direction?: "asc" | "desc"; } const props = withDefaults(defineProps(), { available: () => new Set(), current: "", visible: () => new Set(), + direction: "asc", }); +const letters = computed(() => + props.direction === "desc" ? [...ALPHABET].reverse() : ALPHABET, +); + defineEmits<{ (e: "pick", letter: string): void; }>(); @@ -52,7 +66,7 @@ function isActive(letter: string): boolean { + + + playableTooltip(emulator.value)); :show-tooltip="false" /> - - + +
@@ -171,10 +168,6 @@ const playableLabel = computed(() => playableTooltip(emulator.value)); color: var(--r-color-success); } -.plat-tile__playable--off { - color: var(--r-color-fg-faint); -} - .plat-tile:hover .plat-tile__icon { opacity: 1; } diff --git a/frontend/src/v2/composables/useGalleryVirtualItems/index.ts b/frontend/src/v2/composables/useGalleryVirtualItems/index.ts index cb46bca49..508e09977 100644 --- a/frontend/src/v2/composables/useGalleryVirtualItems/index.ts +++ b/frontend/src/v2/composables/useGalleryVirtualItems/index.ts @@ -80,12 +80,14 @@ interface Options { skeletonRowCount?: number; } -const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ#".split(""); +const ALPHABET = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ@".split(""); function normaliseBackendLetter(raw: string): string { - if (!raw) return "#"; + if (!raw) return "@"; const c = raw.charAt(0).toUpperCase(); - return /[A-Z]/.test(c) ? c : "#"; + if (/[A-Z]/.test(c)) return c; + if (/[0-9]/.test(c)) return "#"; + return "@"; } interface LetterRange { diff --git a/frontend/src/v2/lib/forms/RTextField/RTextField.stories.ts b/frontend/src/v2/lib/forms/RTextField/RTextField.stories.ts index 25647041e..764781237 100644 --- a/frontend/src/v2/lib/forms/RTextField/RTextField.stories.ts +++ b/frontend/src/v2/lib/forms/RTextField/RTextField.stories.ts @@ -30,6 +30,7 @@ const meta: Meta = { readonly: { control: "boolean" }, loading: { control: "boolean" }, hint: { control: "text" }, + subtitle: { control: "text" }, error: { control: "boolean" }, errorMessages: { control: "text" }, }, @@ -135,6 +136,30 @@ export const InlineLabel: Story = { }, }; +export const WithSubtitle: Story = { + name: "Subtitle · path under field", + render: () => ({ + components: { RTextField }, + setup: () => ({ + filename: ref("Super Mario World (USA).sfc"), + }), + template: ` +
+ + + +
+ `, + }), +}; + // ── States ────────────────────────────────────────────────────────── export const WithHint: Story = { diff --git a/frontend/src/v2/lib/forms/RTextField/RTextField.vue b/frontend/src/v2/lib/forms/RTextField/RTextField.vue index 2a7c7e910..7a714d3ca 100644 --- a/frontend/src/v2/lib/forms/RTextField/RTextField.vue +++ b/frontend/src/v2/lib/forms/RTextField/RTextField.vue @@ -84,6 +84,12 @@ interface Props { * matters. Affects the input/textarea only — labels keep the regular * family so the chrome still reads as a normal form field. */ mono?: boolean; + /** Small context line rendered just below the field box (above the + * details/error row). Mono-styled — used for file paths, URLs, + * hashes, or any "this is where the value resolves to" hint that + * pairs with the field's value. The `#subtitle` slot wins over the + * prop when both are provided; use the slot to drop in an icon. */ + subtitle?: string; } const props = withDefaults(defineProps(), { @@ -114,6 +120,7 @@ const props = withDefaults(defineProps(), { multiline: false, rows: 4, mono: false, + subtitle: undefined, }); const emit = defineEmits<{ @@ -294,6 +301,8 @@ const hasAppendInner = computed( const inlineLabelOn = computed(() => props.prefixLabel === "inline"); const stackedLabelOn = computed(() => props.prefixLabel === "stacked"); +const hasSubtitle = computed(() => !!props.subtitle || !!slots.subtitle); + // When `label` is set without a `prefixLabel`, we don't render a // visible label — fall back to the label as placeholder + aria-label // so the field still reads what it's for. Consumers wanting a visible @@ -306,14 +315,30 @@ const effectiveAriaLabel = computed(() => ); // True when the parent is subscribed to a click on the adornment. -// Vue normalises `@click:append-inner` to the key `onClick:appendInner` -// in `$attrs`. The fallback handles older codepaths that camelCase the -// whole name. When subscribed, the adornment renders as a focusable -// `
+ +
+ {{ subtitle }} +
+
("asc"); // `?kind=` URL-synced filter — same direction rules as // `useTileSearchUrl`: route → ref on every change, ref → router.replace @@ -183,14 +184,21 @@ const filtered = computed(() => { return byTerm; }); +// Sort comparator for grid mode — the toolbar asc/desc toggle drives +// direction, name is the only sort axis the grid surface exposes. +function gridCompare(a: CollectionTileEntry, b: CollectionTileEntry): number { + const sign = gridSortDir.value === "asc" ? 1 : -1; + return a.name.localeCompare(b.name) * sign; +} + // Curated = regular + smart (both real, hand-managed). Virtual is the // dynamic/computed kind. Splitting up front keeps every render branch // (flat / letter / list) free of inline kind checks. const curatedTiles = computed(() => - filtered.value.filter((c) => c.kind !== "virtual"), + [...filtered.value.filter((c) => c.kind !== "virtual")].sort(gridCompare), ); const virtualTiles = computed(() => - filtered.value.filter((c) => c.kind === "virtual"), + [...filtered.value.filter((c) => c.kind === "virtual")].sort(gridCompare), ); const totalCount = computed(() => tiles.value.length); @@ -202,22 +210,38 @@ const noResults = computed( ); type LetterGroup = { letter: string; items: CollectionTileEntry[] }; +// Bucket visual order in asc: `# A…Z @` — `#` (digits) first, `@` +// (other symbols) last; mirrors AlphaStrip's ALPHABET. Desc flips the +// whole sequence (`@ Z…A #`). +const COLLECTION_BUCKET_ORDER = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ@"; function groupByLetter(items: CollectionTileEntry[]): LetterGroup[] { - const sorted = [...items].sort((a, b) => a.name.localeCompare(b.name)); + // `items` is pre-sorted by `gridCompare` (see curatedTiles / + // virtualTiles); Array.push + Map iteration preserve insertion order + // so items inside each bucket inherit that direction. + // + // Non-letter first chars split into two distinct buckets so digits + // and other symbols read as separate sections: + // * "#" — digits (0-9) + // * "@" — anything else const map = new Map(); - for (const c of sorted) { + for (const c of items) { const ch = c.name.charAt(0).toUpperCase(); - const key = /[A-Z]/.test(ch) ? ch : "#"; + let key: string; + if (/[A-Z]/.test(ch)) key = ch; + else if (/[0-9]/.test(ch)) key = "#"; + else key = "@"; const bucket = map.get(key); if (bucket) bucket.push(c); else map.set(key, [c]); } + const dirSign = gridSortDir.value === "asc" ? 1 : -1; return [...map.entries()] - .sort(([a], [b]) => { - if (a === "#") return 1; - if (b === "#") return -1; - return a.localeCompare(b); - }) + .sort( + ([a], [b]) => + (COLLECTION_BUCKET_ORDER.indexOf(a) - + COLLECTION_BUCKET_ORDER.indexOf(b)) * + dirSign, + ) .map(([letter, items]) => ({ letter, items })); } const curatedLetterGroups = computed(() => @@ -253,6 +277,7 @@ const showVirtualSection = computed( diff --git a/frontend/src/v2/views/PlatformsIndex.vue b/frontend/src/v2/views/PlatformsIndex.vue index 539ba29be..0f59f1a3b 100644 --- a/frontend/src/v2/views/PlatformsIndex.vue +++ b/frontend/src/v2/views/PlatformsIndex.vue @@ -55,55 +55,88 @@ const playableById = computed(() => { return map; }); -// Sort state — local to this view (the platforms index is small enough -// that a URL round-trip is overkill; debt item if/when we make this -// bookmarkable). -const sortKey = ref("name"); -const sortDir = ref<"asc" | "desc">("asc"); +// Two independent sort states. The list view's column headers drive +// `listSortKey` + `listSortDir`; the grid view's toolbar asc/desc toggle +// drives `gridSortDir`, with the implicit axis tied to the active +// groupBy (letter → name, family → family, …, none → name). Keeping +// them separate so flipping one mode doesn't reshuffle the other. +const listSortKey = ref("name"); +const listSortDir = ref<"asc" | "desc">("asc"); +const gridSortDir = ref<"asc" | "desc">("asc"); -function onSort({ key, dir }: { key: PlatformSortKey; dir: "asc" | "desc" }) { - sortKey.value = key; - sortDir.value = dir; +function onListSort({ + key, + dir, +}: { + key: PlatformSortKey; + dir: "asc" | "desc"; +}) { + listSortKey.value = key; + listSortDir.value = dir; } -// Comparator pulled out so the flat list and each bucket can share it. -// `name` is the secondary tiebreaker for every other column so equal -// values still land in a stable alphabetical order. -function compare(a: Platform, b: Platform): number { - const dir = sortDir.value === "asc" ? 1 : -1; +// Sort axis the grid view should use, derived from the active groupBy. +// Grid has no column headers — the bucket axis is the natural sort axis, +// the toolbar asc/desc toggle is the only direction control. +const gridSortKey = computed(() => { + switch (groupBy.value) { + case "family": + return "family"; + case "category": + return "category"; + case "generation": + return "generation"; + case "playable": + return "playable"; + default: + return "name"; + } +}); + +// Pure comparator parameterised by (key, dir). Both sort states feed it +// to produce their respective sorted arrays. `name` is the secondary +// tiebreaker for every other column so equal values still land in a +// stable alphabetical order. +function compareBy( + a: Platform, + b: Platform, + key: PlatformSortKey, + dir: "asc" | "desc", +): number { + const sign = dir === "asc" ? 1 : -1; const byName = a.display_name.localeCompare(b.display_name); - switch (sortKey.value) { + switch (key) { case "name": - return byName * dir; + return byName * sign; case "family": { const af = a.family_name ?? ""; const bf = b.family_name ?? ""; const cmp = af.localeCompare(bf); - return (cmp || byName) * dir; + return (cmp || byName) * sign; } case "category": { const ac = a.category ?? ""; const bc = b.category ?? ""; const cmp = ac.localeCompare(bc); - return (cmp || byName) * dir; + return (cmp || byName) * sign; } case "generation": { const ag = a.generation ?? -1; const bg = b.generation ?? -1; const cmp = ag - bg; - return (cmp || byName) * dir; + return (cmp || byName) * sign; } case "playable": { const ap = playableById.value.get(a.id) ? 1 : 0; const bp = playableById.value.get(b.id) ? 1 : 0; const cmp = ap - bp; - return (cmp || byName) * dir; + return (cmp || byName) * sign; } case "rom_count": { const ar = a.rom_count ?? 0; const br = b.rom_count ?? 0; const cmp = ar - br; - return (cmp || byName) * dir; + return (cmp || byName) * sign; } } } @@ -164,11 +197,19 @@ const filtered = computed(() => { ); }); -// Sorted view of the filtered list. Single source of truth feeding both -// the flat layouts and the bucket builders (which preserve insertion -// order, so items inside each bucket inherit this sort). -const sorted = computed(() => { - return [...filtered.value].sort(compare); +// Per-mode sorted views. Grid uses the toolbar asc/desc + groupBy axis; +// list uses the column-header click state. Buckets are always fed the +// grid-sorted array (Map iteration preserves insertion order, so items +// inside each bucket inherit that order). +const sortedForGrid = computed(() => { + return [...filtered.value].sort((a, b) => + compareBy(a, b, gridSortKey.value, gridSortDir.value), + ); +}); +const sortedForList = computed(() => { + return [...filtered.value].sort((a, b) => + compareBy(a, b, listSortKey.value, listSortDir.value), + ); }); const totalCount = computed(() => filledPlatforms.value.length); @@ -202,32 +243,34 @@ function bucketBy( return [...map.values()].sort(sort); } -// Letter buckets. Non-alpha first chars roll up under "#" so Greek / -// numeric / symbol-prefixed platform names still land in a stable -// section. -const letterGroups = computed(() => - bucketBy( - sorted.value, +// Letter buckets. Non-letter first chars split into two head buckets so +// the user can tell digits apart from other symbols at a glance: +// * "#" — digits (0-9) +// * "@" — anything else (Greek, punctuation, etc.) +// Order in asc: `# A…Z @` — `#` first, `@` last (matches AlphaStrip's +// ALPHABET). Desc flips the whole sequence (`@ Z…A #`). +const BUCKET_ORDER = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ@"; +const letterGroups = computed(() => { + const dirSign = gridSortDir.value === "asc" ? 1 : -1; + return bucketBy( + sortedForGrid.value, (p) => { const ch = p.display_name.charAt(0).toUpperCase(); - const key = /[A-Z]/.test(ch) ? ch : "#"; - return { key, label: key }; + if (/[A-Z]/.test(ch)) return { key: ch, label: ch }; + if (/[0-9]/.test(ch)) return { key: "#", label: "#" }; + return { key: "@", label: "@" }; }, - (a, b) => { - // "#" sorts after letters so the alphabetical run is unbroken. - if (a.key === "#") return 1; - if (b.key === "#") return -1; - return a.key.localeCompare(b.key); - }, - ), -); + (a, b) => + (BUCKET_ORDER.indexOf(a.key) - BUCKET_ORDER.indexOf(b.key)) * dirSign, + ); +}); // Family buckets. `family_slug` is the stable id (cheap to use as a // Map key); `family_name` is what the user reads. Platforms without a // family land in "Other" and sort last. const familyGroups = computed(() => bucketBy( - sorted.value, + sortedForGrid.value, (p) => { const slug = p.family_slug; const name = p.family_name; @@ -248,7 +291,7 @@ const familyGroups = computed(() => // label without altering the underlying key. const categoryGroups = computed(() => bucketBy( - sorted.value, + sortedForGrid.value, (p) => { const c = p.category; if (c) return { key: c, label: prettifyPlatformCategory(c) }; @@ -267,7 +310,7 @@ const categoryGroups = computed(() => // list-mode metadata column and the group heading agree word-for-word. const generationGroups = computed(() => bucketBy( - sorted.value, + sortedForGrid.value, (p) => { const g = p.generation; if (typeof g === "number" && g > 0) { @@ -292,7 +335,7 @@ const generationGroups = computed(() => // top regardless of sort direction. const playableGroups = computed(() => bucketBy( - sorted.value, + sortedForGrid.value, (p) => playableById.value.get(p.id) ? { key: "playable", label: "Playable" } @@ -336,21 +379,23 @@ const groupedBuckets = computed(() => { @@ -381,7 +426,7 @@ const groupedBuckets = computed(() => { would have separated them. -->
(() => {