From d3833ca817c8649f2b65b229b03532eed6512245 Mon Sep 17 00:00:00 2001 From: Sam Dornan Date: Tue, 15 Sep 2026 02:31:40 +0000 Subject: [PATCH] fix(frontend-v2): centre the recommendation caption under the card The caption under a recommended game card was left-aligned while the card title above it was centred. Centre the caption instead of left-aligning the title, so the change stays inside the recommendation feed rather than shifting every GameCard in the gallery, the similar-games grids and the match-ROM picker. Two things stood in the way of centring: - "Because you played X" never fit the cover width, so it filled the caption and could not centre. It now captions the seed game on its own, with a play icon, the way every facet reason is captioned; the full sentence moves to the title tooltip, so no locale keys change. - The ellipsis sat on the flex container, where it does nothing: an anonymous text run has no box to truncate, so an over-long caption was cut mid-word. It now lives on a real child span. Also nudge the reason icon onto the caption's optical centre. MDI glyphs centre on the em box, leaving them ~2px low against the text's cap height. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01427KQPf6WHJQ8feMKYp24Z --- .../shared/RecommendationReason.vue | 58 ++++++++++++++----- frontend/src/v2/views/Home.test.ts | 6 +- frontend/src/v2/views/Home.vue | 8 +-- 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/frontend/src/v2/components/shared/RecommendationReason.vue b/frontend/src/v2/components/shared/RecommendationReason.vue index fd94c6f7e..f63c64078 100644 --- a/frontend/src/v2/components/shared/RecommendationReason.vue +++ b/frontend/src/v2/components/shared/RecommendationReason.vue @@ -7,31 +7,44 @@ import { useI18n } from "vue-i18n"; import type { SimilarityReasonSchema } from "@/__generated__"; import { reasonIcon, reasonLabel } from "@/v2/utils/similarityReasons"; +const SEED_ICON = "mdi-play"; + const props = defineProps<{ reasons: SimilarityReasonSchema[]; - // Takes the place of the facet chip where the feed knows the seed game, - // e.g. "Because you played Super Metroid". - label?: string | null; + // Captions the card with the game the recommendation came from, in place + // of the first facet. + seedRomName?: string | null; }>(); const { t } = useI18n(); const reason = computed(() => - props.label ? null : (props.reasons[0] ?? null), + props.seedRomName ? null : (props.reasons[0] ?? null), +); + +const icon = computed(() => { + if (props.seedRomName) return SEED_ICON; + return reason.value ? reasonIcon(reason.value) : null; +}); + +const text = computed(() => { + if (props.seedRomName) return props.seedRomName; + return reason.value ? reasonLabel(reason.value, t) : null; +}); + +// The seed name alone fits the card where the full sentence never did, so +// the sentence lives here. +const title = computed(() => + props.seedRomName + ? t("recommendations.because-you-played", [props.seedRomName]) + : t("recommendations.why"), ); @@ -43,11 +56,28 @@ const reason = computed(() => /* Clip to the card it captions rather than widening the row's scroll track; the token tracks the per-breakpoint card width. */ max-width: var(--r-card-art-w); + /* Centres the caption under the card's centred title. Auto margins, not + `justify-content`, so an over-long caption still truncates from one end. */ + margin-inline: auto; overflow: hidden; font-size: 10.5px; font-weight: var(--r-font-weight-medium); color: var(--r-color-fg-faint); white-space: nowrap; +} + +/* The caption is a flex container, so the ellipsis has to live on a real + child: an anonymous text run never truncates, it just gets cut off. */ +.rec-reason__text { + min-width: 0; + overflow: hidden; text-overflow: ellipsis; } + +.rec-reason__icon { + /* MDI glyphs centre on the em box, which the text's descender space drops + ~2px below its optical centre. Transform, not margin: centring absorbs + half of a margin, and a whole pixel stays crisp at 1x. */ + transform: translateY(-1px); +} diff --git a/frontend/src/v2/views/Home.test.ts b/frontend/src/v2/views/Home.test.ts index c9402de9a..39d8113e7 100644 --- a/frontend/src/v2/views/Home.test.ts +++ b/frontend/src/v2/views/Home.test.ts @@ -243,7 +243,11 @@ describe("Home", () => { await flushPromises(); expect(getRecommendedRoms).toHaveBeenCalledTimes(1); - expect(wrapper.text()).toContain("recommendations.because-you-played"); + const caption = wrapper.find(".rec-reason"); + expect(caption.text()).toBe("Super Metroid"); + expect(caption.attributes("title")).toContain( + "recommendations.because-you-played", + ); }); it("hides the recommendations row when the feed comes back empty", async () => { diff --git a/frontend/src/v2/views/Home.vue b/frontend/src/v2/views/Home.vue index 3cb460c15..62ece3b69 100644 --- a/frontend/src/v2/views/Home.vue +++ b/frontend/src/v2/views/Home.vue @@ -436,13 +436,7 @@ function collectionCovers(c: { />