From b738c27507203bdaa9903de0f599f53892f06bf3 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Tue, 14 Apr 2026 10:32:28 -0600 Subject: [PATCH] fix(home): plumb album awards through backend + invalidate stale home cache The ribbon feature relied on album.awards arriving on the frontend, but the DiscoverAlbum Rust struct in both qbz-models and src-tauri/api was missing the 'awards' field, so serde silently dropped it during deserialization of /discover/index. Result: frontend always saw an empty awards array and pickAlbumRibbon returned undefined. Also bumps the home sessionStorage cache to schemaVersion 2 so pre-fix caches (which persisted AlbumCardData without ribbon) are discarded on next launch instead of rehydrating with missing fields. cc --- crates/qbz-models/src/types.rs | 4 ++++ src-tauri/src/api/models.rs | 4 ++++ src/lib/stores/homeDataCache.ts | 19 +++++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/qbz-models/src/types.rs b/crates/qbz-models/src/types.rs index c5b3079ff..b426c7408 100644 --- a/crates/qbz-models/src/types.rs +++ b/crates/qbz-models/src/types.rs @@ -631,6 +631,10 @@ pub struct DiscoverAlbum { pub genre: Option, pub dates: Option, pub audio_info: Option, + /// Editorial awards attached to the album. Id 88 = Qobuzissime, + /// id 151 = Qobuz Album of the Week (locale-stable). + #[serde(default)] + pub awards: Option>, } /// Album image from discover endpoint diff --git a/src-tauri/src/api/models.rs b/src-tauri/src/api/models.rs index d0f81f566..82c384abb 100644 --- a/src-tauri/src/api/models.rs +++ b/src-tauri/src/api/models.rs @@ -811,6 +811,10 @@ pub struct DiscoverAlbum { pub genre: Option, pub dates: Option, pub audio_info: Option, + /// Editorial awards attached to the album. Id 88 = Qobuzissime, + /// id 151 = Qobuz Album of the Week (locale-stable). + #[serde(default)] + pub awards: Option>, } /// Album image from discover endpoint diff --git a/src/lib/stores/homeDataCache.ts b/src/lib/stores/homeDataCache.ts index afce22627..c8ac27c3a 100644 --- a/src/lib/stores/homeDataCache.ts +++ b/src/lib/stores/homeDataCache.ts @@ -55,6 +55,7 @@ export interface HomeCacheData { timestamp: number; genreIds: number[]; // snapshot of genre filter at cache time scrollTop: number; + schemaVersion?: number; } export type HomeCacheStatus = 'fresh' | 'stale' | 'empty'; @@ -62,6 +63,13 @@ export type HomeCacheStatus = 'fresh' | 'stale' | 'empty'; const FRESH_TTL_MS = 5 * 60 * 1000; // 5 minutes const MAX_TTL_MS = 60 * 60 * 1000; // 60 minutes const SESSION_KEY = 'qbz-home-cache'; +/** + * Bump whenever the shape of HomeCacheData or AlbumCardData changes, + * so stale sessionStorage entries from older builds are discarded + * instead of being restored with missing fields (which caused the + * ribbon field to show up as undefined on cache-fresh loads). + */ +const CACHE_SCHEMA_VERSION = 2; let cache: HomeCacheData | null = null; @@ -70,7 +78,13 @@ function restoreFromSession(): void { try { const stored = sessionStorage.getItem(SESSION_KEY); if (stored) { - cache = JSON.parse(stored); + const parsed = JSON.parse(stored); + if (parsed?.schemaVersion === CACHE_SCHEMA_VERSION) { + cache = parsed; + } else { + // Older schema — drop it so loadHome() runs fresh. + try { sessionStorage.removeItem(SESSION_KEY); } catch {} + } } } catch { // sessionStorage not available or corrupted @@ -129,7 +143,8 @@ export function setHomeCache(data: Omit