fix(genre): load all genres including sub-genres

Fetch parent genres first, then fetch sub-genres for each parent in
parallel. Combine into a flat list sorted alphabetically. This fixes
the issue where albums with sub-genres (like Alternative & Indie,
Opera, Concertos) were filtered out even when all genres were selected.
This commit is contained in:
vicrodh committed 2026-02-02 10:18:57 -06:00
1 parent df7a7e2cb5
commit d2544dceb9
1 file changed
+27 -3
+27 -3
View File
@@ -105,15 +105,39 @@ export async function loadGenres(): Promise<void> {
notify('favorites'); notify('favorites');
try { try {
const genres = await invoke<GenreInfo[]>('get_genres', {}); // Fetch top-level genres first
state.availableGenres = genres; const parentGenres = await invoke<GenreInfo[]>('get_genres', {});
// Fetch sub-genres for each parent in parallel
const subGenrePromises = parentGenres.map(async (parent) => {
try {
const children = await invoke<GenreInfo[]>('get_genres', { parentId: parent.id });
return children;
} catch {
return [];
}
});
const subGenreResults = await Promise.all(subGenrePromises);
const allSubGenres = subGenreResults.flat();
// Combine all genres and remove duplicates by ID
const allGenres = [...parentGenres, ...allSubGenres];
const uniqueGenres = Array.from(
new Map(allGenres.map(g => [g.id, g])).values()
);
// Sort alphabetically by name
uniqueGenres.sort((a, b) => a.name.localeCompare(b.name));
state.availableGenres = uniqueGenres;
// Load saved selections for all contexts // Load saved selections for all contexts
loadFromStorage('home'); loadFromStorage('home');
loadFromStorage('favorites'); loadFromStorage('favorites');
// Validate saved selections against available genres // Validate saved selections against available genres
const validIds = new Set(genres.map((g) => g.id)); const validIds = new Set(uniqueGenres.map((g) => g.id));
for (const ctx of ['home', 'favorites'] as GenreFilterContext[]) { for (const ctx of ['home', 'favorites'] as GenreFilterContext[]) {
const ctxState = state.contexts[ctx]; const ctxState = state.contexts[ctx];
const validSelection = new Set<number>(); const validSelection = new Set<number>();