Files
Psychotoxical-psysonic/src/pages/Tracks.tsx
T
Frank Stellmacher 3b94368ffa fix(ui): visual consistency sweep — shapes, buttons, hero, header alignment (#745)
* fix(ui): square shape across badges, pills and non-player buttons

zunoz on Discord flagged inconsistent shapes for play buttons, badges
and pills across the app. Unify to var(--radius-sm) for non-player
surfaces so the same visual indicator looks identical wherever it
appears. Player Bar, Fullscreen Player and Mini Player keep their
circular shape as part of the player family; toggle switches, sliders,
search input, pagination dots and theme overrides are left alone.

Covers: hero play + nav arrows, album-card details button, album
header icon buttons, playlist suggestion play, album-row nav arrows;
.badge (incl. New / album-detail), genre pill, np chip/tag/badge,
np-dash toolbar badge, radio filter chip, radio card chip, mp album
plays pill, settings search-result badge, alphabet filter buttons,
download hint, mobile search chip, artist release-group count, artist
external link, all Orbit session pills, device-sync count badge;
ServersTab "Aktiv" badge, PlaylistCard loading badge, AlbumRow /
ArtistRow "more" buttons.

* fix(composers): collapse empty space between virtual rows

The composer grid uses text-only tiles (~78 px intrinsic) but
estimateRowHeightPx scaled with cell width like the image variants,
clamped to a 200 px maximum. On normal viewports every virtual row
reserved ~200 px while the actual card was ~78 px, leaving ~120 px of
empty space below each row.

Pin the composer variant to min === max so the rowHeight is a fixed
88 px regardless of cell width.

* fix(ui): unify secondary action buttons on btn-surface

Action rows on the Artist, Album, Tracks, Favorites and Most Played
pages mixed btn-ghost (borderless), btn-surface (bordered) and bare
.btn (no variant, picked up bordered look in light themes only).
Result was per-page and per-theme inconsistency — secondary buttons
sometimes had borders, sometimes not.

Unify on btn-surface for all secondary actions so the same affordance
looks identical across pages and the difference between themes is just
border tone, not border presence.

- Tracks hero: Enqueue and Reroll buttons
- AlbumHeader: Shuffle, Enqueue, Star, Share, Bio, Download and the
  Offline-cache states
- MostPlayed: sort toggle and compilations filter (now matches the
  Albums page header)

* fix(hero): make pagination dots visible on light backdrops

The pagination dots used `rgba(255, 255, 255, 0.35)` which disappears
against white-dominant cover art and on light themes, even under the
hero gradient overlay. zunoz on Discord reported the inactive dots as
effectively invisible.

Bump inactive dots to 85 % white with a dark outline + drop shadow so
they read against any backdrop, and switch the active dot to the
accent color so the highlight reads as colour, not just width.

Also opaque-fill `.badge` (`var(--accent)` + `--ctp-crust` text) so the
hero pills do not disappear against light cover art either — base
class previously used `--accent-dim` which is too transparent for
badges per the existing badge rule.

* fix(tracks): align Browse-all-tracks header with rows

The Tracks page header sat outside the scroll container while rows
sat inside it, so the scrollbar gutter shrank only the rows and the
last header column drifted right of its row data. With OpenDyslexic
selected the wider glyphs pushed "Duration" past the viewport edge
entirely; zunoz on Discord reported it.

Move SongListHeader inside the scroll container with position:
sticky so header and rows share the same width budget. Sticky
keeps the header visible while scrolling as a side benefit.

* test(cardGridLayout): pin composer variant to fixed row height

Guards the fix that collapsed the empty space between Composers grid
rows. Re-introducing the `cellWidthPx + extra` scaling for composer
would silently bring back ~120 px of dead space per virtual row, so
the test asserts the fixed 88 px output across a wide cellWidth range.

Image variants (artist / album / playlist) get baseline assertions so
the composer case is documented as the deliberate exception, not an
oversight.

* docs(changelog): UI consistency sweep (PR #745)
2026-05-17 12:32:43 +02:00

214 lines
7.9 KiB
TypeScript

import { buildCoverArtUrl, coverArtCacheKey } from '../api/subsonicStreamUrl';
import { getRandomSongs } from '../api/subsonicLibrary';
import type { SubsonicSong } from '../api/subsonicTypes';
import { songToTrack } from '../utils/playback/songToTrack';
import React, { useEffect, useState, useCallback, useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
import { Play, ListPlus, RefreshCw, Sparkles } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { useAuthStore } from '../store/authStore';
import { usePlayerStore } from '../store/playerStore';
import CachedImage from '../components/CachedImage';
import SongRail from '../components/SongRail';
import VirtualSongList from '../components/VirtualSongList';
import { playSongNow } from '../utils/playback/playSong';
import { ndListSongs, ndInvalidateSongsCache } from '../api/navidromeBrowse';
import { usePerfProbeFlags } from '../utils/perf/perfFlags';
const RANDOM_RAIL_SIZE = 18;
/** Over-fetch buffer so the client-side `userRating > 0` filter still leaves
* enough cards for the rail. Server-side rating filter on Navidrome's REST
* is finicky and not yet wired through — revisit when verified. */
const RATED_RAIL_FETCH = 60;
const RATED_RAIL_DISPLAY = 30;
/** Stay-fresh window for the Highly Rated rail. Cleared on rating mutation, so
* the only staleness path is a reroll-button click after >60 s. */
const RATED_RAIL_CACHE_MS = 60_000;
/** Match Home: only mount artwork for cards near the horizontal viewport. */
const TRACKS_SONG_RAIL_WINDOWING = true;
const TRACKS_SONG_RAIL_INITIAL_ARTWORK_BUDGET = 14;
export default function Tracks() {
const perfFlags = usePerfProbeFlags();
const { t } = useTranslation();
const navigate = useNavigate();
const activeServerId = useAuthStore(s => s.activeServerId);
const enqueue = usePlayerStore(s => s.enqueue);
const [hero, setHero] = useState<SubsonicSong | null>(null);
const [heroLoading, setHeroLoading] = useState(false);
const [random, setRandom] = useState<SubsonicSong[]>([]);
const [randomLoading, setRandomLoading] = useState(true);
const [rated, setRated] = useState<SubsonicSong[]>([]);
const [ratedLoading, setRatedLoading] = useState(true);
/** Hide the rail entirely on non-Navidrome servers (REST call throws) so we don't show an empty section. */
const [ratedSupported, setRatedSupported] = useState(true);
const rerollHero = useCallback(async () => {
setHeroLoading(true);
try {
const picks = await getRandomSongs(1);
if (picks[0]) setHero(picks[0]);
} finally {
setHeroLoading(false);
}
}, []);
const rerollRandom = useCallback(async () => {
setRandomLoading(true);
try {
const r = await getRandomSongs(RANDOM_RAIL_SIZE);
setRandom(r);
} finally {
setRandomLoading(false);
}
}, []);
const reloadRated = useCallback(async () => {
setRatedLoading(true);
try {
const songs = await ndListSongs(0, RATED_RAIL_FETCH, 'rating', 'DESC', RATED_RAIL_CACHE_MS);
const filtered = songs.filter(s => (s.userRating ?? 0) > 0).slice(0, RATED_RAIL_DISPLAY);
setRated(filtered);
setRatedSupported(true);
} catch {
// Non-Navidrome server, or REST endpoint refused → silently hide the rail.
setRated([]);
setRatedSupported(false);
} finally {
setRatedLoading(false);
}
}, []);
useEffect(() => {
if (!activeServerId) return;
rerollHero();
rerollRandom();
reloadRated();
}, [activeServerId, rerollHero, rerollRandom, reloadRated]);
const heroCoverUrl = useMemo(
() => (hero?.coverArt ? buildCoverArtUrl(hero.coverArt, 600) : ''),
[hero?.coverArt],
);
const heroCoverKey = useMemo(
() => (hero?.coverArt ? coverArtCacheKey(hero.coverArt, 600) : ''),
[hero?.coverArt],
);
// Hide the hero song from the random rail if the server happens to return it in
// both fetches (Navidrome's getRandomSongs sometimes overlaps within a short window).
const railSongs = useMemo(
() => (hero ? random.filter(s => s.id !== hero.id) : random),
[random, hero],
);
return (
<div className="content-body animate-fade-in tracks-page">
{!perfFlags.disableMainstageStickyHeader && (
<header className="tracks-header">
<div className="tracks-header-text">
<h1 className="page-title">{t('tracks.title')}</h1>
<p className="tracks-subtitle">{t('tracks.subtitle')}</p>
</div>
</header>
)}
{!perfFlags.disableMainstageHero && hero && (
<section className="tracks-hero">
<div className="tracks-hero-cover">
{heroCoverUrl ? (
<CachedImage
src={heroCoverUrl}
cacheKey={heroCoverKey}
alt=""
/>
) : (
<div className="tracks-hero-cover-placeholder" />
)}
</div>
<div className="tracks-hero-content">
<span className="tracks-hero-eyebrow">
<Sparkles size={14} />
{t('tracks.heroEyebrow')}
</span>
<h2 className="tracks-hero-title" title={hero.title}>{hero.title}</h2>
<p className="tracks-hero-meta">
<span
className={hero.artistId ? 'track-artist-link' : ''}
style={{ cursor: hero.artistId ? 'pointer' : 'default' }}
onClick={() => hero.artistId && navigate(`/artist/${hero.artistId}`)}
>{hero.artist}</span>
{hero.album && (
<>
<span className="tracks-hero-meta-dot">·</span>
<span
className={hero.albumId ? 'track-artist-link' : ''}
style={{ cursor: hero.albumId ? 'pointer' : 'default' }}
onClick={() => hero.albumId && navigate(`/album/${hero.albumId}`)}
>{hero.album}</span>
</>
)}
</p>
<div className="tracks-hero-actions">
<button
className="btn btn-primary"
onClick={() => playSongNow(hero)}
>
<Play size={16} fill="currentColor" /> {t('tracks.playSong')}
</button>
<button
className="btn btn-surface"
onClick={() => enqueue([songToTrack(hero)])}
>
<ListPlus size={16} /> {t('tracks.enqueueSong')}
</button>
<button
className="btn btn-surface"
onClick={rerollHero}
disabled={heroLoading}
aria-label={t('tracks.heroReroll')}
data-tooltip={t('tracks.heroReroll')}
data-tooltip-pos="top"
>
<RefreshCw size={16} className={heroLoading ? 'is-spinning' : ''} />
</button>
</div>
</div>
</section>
)}
{!perfFlags.disableMainstageRails && ratedSupported && (ratedLoading || rated.length > 0) && (
<SongRail
title={t('tracks.railHighlyRated')}
songs={rated}
loading={ratedLoading}
onReroll={() => { ndInvalidateSongsCache(); return reloadRated(); }}
windowArtworkByViewport={TRACKS_SONG_RAIL_WINDOWING}
initialArtworkBudget={TRACKS_SONG_RAIL_INITIAL_ARTWORK_BUDGET}
/>
)}
{!perfFlags.disableMainstageRails && (
<SongRail
title={t('tracks.railRandom')}
songs={railSongs}
loading={randomLoading}
onReroll={rerollRandom}
windowArtworkByViewport={TRACKS_SONG_RAIL_WINDOWING}
initialArtworkBudget={TRACKS_SONG_RAIL_INITIAL_ARTWORK_BUDGET}
/>
)}
{!perfFlags.disableMainstageVirtualLists && (
<VirtualSongList
title={t('tracks.browseTitle')}
emptyBrowseText={t('tracks.browseUnsupported')}
/>
)}
</div>
);
}