fix: use existing genre filter, fix ranking display and See All positioning
- Replace custom genre <select> with GenreFilterButton component, each discover page gets independent persistence via separate contexts - Rank badge in grid mode: 3x bigger (33px), positioned on right side of album card, no # symbol - See All link: pushed to right edge (margin-left: auto), color matches nav buttons (#666666), hover transitions to text-primary - Add proper page padding to DiscoverBrowseView (18px left, 8px right)
This commit is contained in:
1 parent
c9bdcae855
commit
a575c0c805
4 files changed
+69
-64
No files matched your search
@@ -308,7 +308,7 @@
|
||||
{#each item.albums as album, idx (album.id)}
|
||||
<div class="grid-card-wrapper">
|
||||
{#if showRanking}
|
||||
<div class="rank-badge">#{item.startIndex + idx + 1}</div>
|
||||
<div class="rank-badge">{item.startIndex + idx + 1}</div>
|
||||
{/if}
|
||||
<AlbumCard
|
||||
albumId={album.id}
|
||||
@@ -524,16 +524,17 @@
|
||||
|
||||
.rank-badge {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
left: 4px;
|
||||
bottom: 114px;
|
||||
right: 4px;
|
||||
z-index: 2;
|
||||
background: rgba(0, 0, 0, 0.75);
|
||||
background: rgba(0, 0, 0, 0.70);
|
||||
color: #fff;
|
||||
font-size: 11px;
|
||||
font-size: 33px;
|
||||
font-weight: 700;
|
||||
padding: 2px 6px;
|
||||
border-radius: 6px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 8px;
|
||||
pointer-events: none;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.rank-number {
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
import { t } from '$lib/i18n';
|
||||
import { ChevronLeft, Search, LayoutGrid, List, X } from 'lucide-svelte';
|
||||
import VirtualizedFavoritesAlbumGrid from '../VirtualizedFavoritesAlbumGrid.svelte';
|
||||
import GenreFilterButton from '../GenreFilterButton.svelte';
|
||||
import {
|
||||
getSelectedGenreIds,
|
||||
type GenreFilterContext
|
||||
} from '$lib/stores/genreFilterStore';
|
||||
|
||||
interface DiscoverAlbum {
|
||||
id: string;
|
||||
@@ -36,11 +41,6 @@
|
||||
maximum_sampling_rate?: number;
|
||||
}
|
||||
|
||||
interface GenreInfo {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
endpointType: 'newReleases' | 'idealDiscography' | 'mostStreamed';
|
||||
titleKey: string;
|
||||
@@ -83,6 +83,14 @@
|
||||
|
||||
const PAGE_SIZE = 50;
|
||||
|
||||
// Map endpointType to GenreFilterContext for independent persistence
|
||||
const GENRE_CONTEXT_MAP: Record<string, GenreFilterContext> = {
|
||||
newReleases: 'discover-new-releases',
|
||||
idealDiscography: 'discover-ideal-discography',
|
||||
mostStreamed: 'discover-top-albums',
|
||||
};
|
||||
const genreContext = GENRE_CONTEXT_MAP[endpointType];
|
||||
|
||||
// State
|
||||
let albums = $state<FavoriteAlbum[]>([]);
|
||||
let hasMore = $state(true);
|
||||
@@ -91,8 +99,6 @@
|
||||
let isLoadingMore = $state(false);
|
||||
let searchQuery = $state('');
|
||||
let viewMode = $state<'grid' | 'list'>('grid');
|
||||
let genres = $state<GenreInfo[]>([]);
|
||||
let selectedGenreId = $state<number | null>(null);
|
||||
let albumDownloadStatuses = $state<Map<string, boolean>>(new Map());
|
||||
|
||||
// Search filter (client-side on loaded items)
|
||||
@@ -147,6 +153,11 @@
|
||||
};
|
||||
}
|
||||
|
||||
function getGenreIdsForFetch(): number[] | undefined {
|
||||
const ids = getSelectedGenreIds(genreContext);
|
||||
return ids.size > 0 ? Array.from(ids) : undefined;
|
||||
}
|
||||
|
||||
async function fetchAlbums(resetData: boolean = false) {
|
||||
if (resetData) {
|
||||
offset = 0;
|
||||
@@ -158,7 +169,7 @@
|
||||
}
|
||||
|
||||
try {
|
||||
const genreIds = selectedGenreId ? [selectedGenreId] : undefined;
|
||||
const genreIds = getGenreIdsForFetch();
|
||||
const response = await invoke<DiscoverAlbumsResponse>('get_discover_albums', {
|
||||
endpointType,
|
||||
genreIds,
|
||||
@@ -193,9 +204,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function handleGenreChange(e: Event) {
|
||||
const select = e.target as HTMLSelectElement;
|
||||
selectedGenreId = select.value ? Number(select.value) : null;
|
||||
function handleGenreFilterChange() {
|
||||
fetchAlbums(true);
|
||||
}
|
||||
|
||||
@@ -203,14 +212,6 @@
|
||||
searchQuery = '';
|
||||
}
|
||||
|
||||
async function loadGenres() {
|
||||
try {
|
||||
genres = await invoke<GenreInfo[]>('get_genres', {});
|
||||
} catch (err) {
|
||||
console.error('Failed to load genres:', err);
|
||||
}
|
||||
}
|
||||
|
||||
function getQualityLabel(item: { hires?: boolean; maximum_bit_depth?: number; maximum_sampling_rate?: number }): string {
|
||||
if (!item.hires) return 'CD';
|
||||
const depth = item.maximum_bit_depth ?? 16;
|
||||
@@ -225,7 +226,6 @@
|
||||
|
||||
onMount(() => {
|
||||
fetchAlbums(true);
|
||||
loadGenres();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -253,12 +253,7 @@
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
<select class="genre-select" onchange={handleGenreChange} value={selectedGenreId ?? ''}>
|
||||
<option value="">{$t('discover.allGenres')}</option>
|
||||
{#each genres as genre (genre.id)}
|
||||
<option value={genre.id}>{genre.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
<GenreFilterButton context={genreContext} variant="control" align="right" onFilterChange={handleGenreFilterChange} />
|
||||
<div class="view-toggle">
|
||||
<button
|
||||
class="toggle-btn"
|
||||
@@ -328,6 +323,9 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
padding: 24px;
|
||||
padding-left: 18px;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
.top-bar {
|
||||
@@ -335,7 +333,7 @@
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
padding: 0 0 16px;
|
||||
padding-bottom: 16px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@@ -417,23 +415,6 @@
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.genre-select {
|
||||
background: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
padding: 6px 12px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
max-width: 160px;
|
||||
}
|
||||
|
||||
.genre-select option {
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.view-toggle {
|
||||
display: flex;
|
||||
background: var(--bg-secondary);
|
||||
|
||||
@@ -1739,16 +1739,17 @@
|
||||
.see-all-link {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--accent-primary, #7c5cbf);
|
||||
color: #666666;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
white-space: nowrap;
|
||||
transition: opacity 150ms ease;
|
||||
margin-left: auto;
|
||||
transition: color 150ms ease;
|
||||
}
|
||||
|
||||
.see-all-link:hover {
|
||||
opacity: 0.8;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
</style>
|
||||
@@ -20,7 +20,7 @@ export interface GenreTreeNode {
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
export type GenreFilterContext = 'home' | 'favorites';
|
||||
export type GenreFilterContext = 'home' | 'favorites' | 'discover-new-releases' | 'discover-ideal-discography' | 'discover-top-albums';
|
||||
|
||||
interface ContextState {
|
||||
selectedGenreIds: Set<number>;
|
||||
@@ -40,6 +40,9 @@ interface GenreFilterState {
|
||||
const STORAGE_KEYS: Record<GenreFilterContext, string> = {
|
||||
home: 'qbz_genre_filter_home',
|
||||
favorites: 'qbz_genre_filter_favorites',
|
||||
'discover-new-releases': 'qbz_genre_filter_discover_new_releases',
|
||||
'discover-ideal-discography': 'qbz_genre_filter_discover_ideal_discography',
|
||||
'discover-top-albums': 'qbz_genre_filter_discover_top_albums',
|
||||
};
|
||||
|
||||
const GENRE_CACHE_KEY = 'qbz_genre_cache';
|
||||
@@ -103,6 +106,21 @@ const state: GenreFilterState = {
|
||||
rememberSelection: true,
|
||||
listeners: new Set(),
|
||||
},
|
||||
'discover-new-releases': {
|
||||
selectedGenreIds: new Set(),
|
||||
rememberSelection: true,
|
||||
listeners: new Set(),
|
||||
},
|
||||
'discover-ideal-discography': {
|
||||
selectedGenreIds: new Set(),
|
||||
rememberSelection: true,
|
||||
listeners: new Set(),
|
||||
},
|
||||
'discover-top-albums': {
|
||||
selectedGenreIds: new Set(),
|
||||
rememberSelection: true,
|
||||
listeners: new Set(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -116,8 +134,9 @@ function notify(context?: GenreFilterContext) {
|
||||
}
|
||||
|
||||
function notifyAll() {
|
||||
notify('home');
|
||||
notify('favorites');
|
||||
for (const ctx of Object.keys(state.contexts) as GenreFilterContext[]) {
|
||||
notify(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
function saveToStorage(context?: GenreFilterContext) {
|
||||
@@ -165,7 +184,7 @@ function validateAndCleanStoredGenreIds(): void {
|
||||
const validIds = new Set(state.allGenres.map(g => g.id));
|
||||
let cleaned = false;
|
||||
|
||||
for (const context of ['home', 'favorites'] as const) {
|
||||
for (const context of Object.keys(state.contexts) as GenreFilterContext[]) {
|
||||
const ctxState = state.contexts[context];
|
||||
const invalidIds: number[] = [];
|
||||
|
||||
@@ -200,8 +219,9 @@ export async function loadGenres(): Promise<void> {
|
||||
state.childrenByParent = new Map(Object.entries(cache.childrenByParent).map(([k, v]) => [Number(k), v]));
|
||||
state.allGenres = [...cache.parentGenres, ...Object.values(cache.childrenByParent).flat()];
|
||||
state.genreTree = buildTreeFromCache(cache);
|
||||
loadFromStorage('home');
|
||||
loadFromStorage('favorites');
|
||||
for (const ctx of Object.keys(state.contexts) as GenreFilterContext[]) {
|
||||
loadFromStorage(ctx);
|
||||
}
|
||||
// Validate stored genre IDs against loaded genres
|
||||
validateAndCleanStoredGenreIds();
|
||||
notifyAll();
|
||||
@@ -270,8 +290,9 @@ export async function loadGenres(): Promise<void> {
|
||||
state.childrenByParent = childrenByParent;
|
||||
|
||||
saveGenreCache();
|
||||
loadFromStorage('home');
|
||||
loadFromStorage('favorites');
|
||||
for (const ctx of Object.keys(state.contexts) as GenreFilterContext[]) {
|
||||
loadFromStorage(ctx);
|
||||
}
|
||||
// Validate stored genre IDs against loaded genres
|
||||
validateAndCleanStoredGenreIds();
|
||||
} catch (e) {
|
||||
@@ -576,5 +597,6 @@ export function subscribe(callback: () => void, context?: GenreFilterContext): (
|
||||
return () => ctxState.listeners.delete(callback);
|
||||
}
|
||||
|
||||
loadFromStorage('home');
|
||||
loadFromStorage('favorites');
|
||||
for (const ctx of Object.keys(STORAGE_KEYS) as GenreFilterContext[]) {
|
||||
loadFromStorage(ctx);
|
||||
}
|
||||
Reference in new issue
Block a user