fix(home): improve loading overlay + favorite button in Continue Listening
Loading overlay: - Wait for ALL visible sections to finish loading before hiding overlay - Count total visible sections and track when each finishes - Content renders behind overlay, then overlay fades out smoothly Continue Listening: - Add menuActions with onAddFavorite to TrackRow - Import handleAddToFavorites from trackActions service - Favorite button now works in Continue Listening section
This commit is contained in:
1 parent
c529a28c6e
commit
48a010c597
1 file changed
+83
-56
@@ -7,6 +7,7 @@
|
|||||||
import TrackRow from '../TrackRow.svelte';
|
import TrackRow from '../TrackRow.svelte';
|
||||||
import HomeSettingsModal from '../HomeSettingsModal.svelte';
|
import HomeSettingsModal from '../HomeSettingsModal.svelte';
|
||||||
import { formatDuration, formatQuality, getQobuzImage } from '$lib/adapters/qobuzAdapters';
|
import { formatDuration, formatQuality, getQobuzImage } from '$lib/adapters/qobuzAdapters';
|
||||||
|
import { handleAddToFavorites } from '$lib/services/trackActions';
|
||||||
import {
|
import {
|
||||||
subscribe as subscribeHomeSettings,
|
subscribe as subscribeHomeSettings,
|
||||||
getSettings,
|
getSettings,
|
||||||
@@ -83,7 +84,7 @@
|
|||||||
|
|
||||||
// Loading states for progressive render
|
// Loading states for progressive render
|
||||||
let isInitializing = $state(true);
|
let isInitializing = $state(true);
|
||||||
let isOverlayVisible = $state(true); // Overlay that fades out when ready
|
let isOverlayVisible = $state(true); // Overlay that fades out when ALL sections ready
|
||||||
let error = $state<string | null>(null);
|
let error = $state<string | null>(null);
|
||||||
let loadingNewReleases = $state(true);
|
let loadingNewReleases = $state(true);
|
||||||
let loadingPressAwards = $state(true);
|
let loadingPressAwards = $state(true);
|
||||||
@@ -95,9 +96,9 @@
|
|||||||
let loadingTopArtists = $state(true);
|
let loadingTopArtists = $state(true);
|
||||||
let loadingFavoriteAlbums = $state(true);
|
let loadingFavoriteAlbums = $state(true);
|
||||||
|
|
||||||
// Track when we have enough content to show
|
// Track loading completion for overlay
|
||||||
let sectionsReady = $state(0);
|
let totalVisibleSections = $state(0);
|
||||||
const MIN_SECTIONS_BEFORE_SHOW = 2; // Wait for at least 2 sections
|
let sectionsFinished = $state(0);
|
||||||
|
|
||||||
// Featured albums (from Qobuz editorial)
|
// Featured albums (from Qobuz editorial)
|
||||||
let newReleases = $state<AlbumCardData[]>([]);
|
let newReleases = $state<AlbumCardData[]>([]);
|
||||||
@@ -126,14 +127,20 @@
|
|||||||
|| favoriteAlbums.length > 0
|
|| favoriteAlbums.length > 0
|
||||||
);
|
);
|
||||||
|
|
||||||
// Mark a section as ready and check if we can hide overlay
|
// Mark a section as finished loading and check if we can hide overlay
|
||||||
function markSectionReady() {
|
function markSectionFinished() {
|
||||||
sectionsReady++;
|
sectionsFinished++;
|
||||||
if (sectionsReady >= MIN_SECTIONS_BEFORE_SHOW && isOverlayVisible) {
|
checkAllSectionsReady();
|
||||||
// Small delay to ensure DOM is ready, then fade out
|
}
|
||||||
|
|
||||||
|
// Check if all visible sections have finished loading
|
||||||
|
function checkAllSectionsReady() {
|
||||||
|
if (sectionsFinished >= totalVisibleSections && totalVisibleSections > 0 && isOverlayVisible) {
|
||||||
|
// Small delay to ensure DOM has rendered, then fade out
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
isOverlayVisible = false;
|
isOverlayVisible = false;
|
||||||
}, 100);
|
isInitializing = false;
|
||||||
|
}, 150);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +280,7 @@
|
|||||||
async function loadHome() {
|
async function loadHome() {
|
||||||
isInitializing = true;
|
isInitializing = true;
|
||||||
isOverlayVisible = true;
|
isOverlayVisible = true;
|
||||||
sectionsReady = 0;
|
sectionsFinished = 0;
|
||||||
error = null;
|
error = null;
|
||||||
loadingNewReleases = true;
|
loadingNewReleases = true;
|
||||||
loadingPressAwards = true;
|
loadingPressAwards = true;
|
||||||
@@ -285,14 +292,32 @@
|
|||||||
loadingTopArtists = true;
|
loadingTopArtists = true;
|
||||||
loadingFavoriteAlbums = true;
|
loadingFavoriteAlbums = true;
|
||||||
|
|
||||||
// Start loading featured albums immediately (no seeds needed)
|
// Count total visible sections to know when we're done
|
||||||
// These show first since they're fast API calls
|
totalVisibleSections = 0;
|
||||||
// Only load if section is visible to save API calls
|
if (isSectionVisible('newReleases')) totalVisibleSections++;
|
||||||
|
if (isSectionVisible('pressAwards')) totalVisibleSections++;
|
||||||
|
if (isSectionVisible('mostStreamed')) totalVisibleSections++;
|
||||||
|
if (isSectionVisible('qobuzissimes')) totalVisibleSections++;
|
||||||
|
if (isSectionVisible('editorPicks')) totalVisibleSections++;
|
||||||
|
if (isSectionVisible('recentAlbums')) totalVisibleSections++;
|
||||||
|
if (isSectionVisible('continueTracks')) totalVisibleSections++;
|
||||||
|
if (isSectionVisible('topArtists')) totalVisibleSections++;
|
||||||
|
if (isSectionVisible('favoriteAlbums')) totalVisibleSections++;
|
||||||
|
|
||||||
|
// Start ML data loading FIRST (local SQLite) - this gets the seeds
|
||||||
|
const mlPromise = invoke<HomeSeeds>('reco_get_home_ml', {
|
||||||
|
limitRecentAlbums: LIMITS.recentAlbums,
|
||||||
|
limitContinueTracks: LIMITS.continueTracks,
|
||||||
|
limitTopArtists: LIMITS.topArtists,
|
||||||
|
limitFavorites: Math.max(LIMITS.favoriteAlbums, LIMITS.favoriteTracks)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Start Qobuz API calls in parallel (don't await)
|
||||||
if (isSectionVisible('newReleases')) {
|
if (isSectionVisible('newReleases')) {
|
||||||
fetchFeaturedAlbums('new-releases', LIMITS.featuredAlbums).then(albums => {
|
fetchFeaturedAlbums('new-releases', LIMITS.featuredAlbums).then(albums => {
|
||||||
newReleases = albums;
|
newReleases = albums;
|
||||||
loadingNewReleases = false;
|
loadingNewReleases = false;
|
||||||
if (albums.length > 0) markSectionReady();
|
markSectionFinished();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
loadingNewReleases = false;
|
loadingNewReleases = false;
|
||||||
@@ -302,7 +327,7 @@
|
|||||||
fetchFeaturedAlbums('press-awards', LIMITS.featuredAlbums).then(albums => {
|
fetchFeaturedAlbums('press-awards', LIMITS.featuredAlbums).then(albums => {
|
||||||
pressAwards = albums;
|
pressAwards = albums;
|
||||||
loadingPressAwards = false;
|
loadingPressAwards = false;
|
||||||
if (albums.length > 0) markSectionReady();
|
markSectionFinished();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
loadingPressAwards = false;
|
loadingPressAwards = false;
|
||||||
@@ -312,7 +337,7 @@
|
|||||||
fetchFeaturedAlbums('most-streamed', LIMITS.featuredAlbums).then(albums => {
|
fetchFeaturedAlbums('most-streamed', LIMITS.featuredAlbums).then(albums => {
|
||||||
mostStreamed = albums;
|
mostStreamed = albums;
|
||||||
loadingMostStreamed = false;
|
loadingMostStreamed = false;
|
||||||
if (albums.length > 0) markSectionReady();
|
markSectionFinished();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
loadingMostStreamed = false;
|
loadingMostStreamed = false;
|
||||||
@@ -322,7 +347,7 @@
|
|||||||
fetchFeaturedAlbums('qobuzissimes', LIMITS.featuredAlbums).then(albums => {
|
fetchFeaturedAlbums('qobuzissimes', LIMITS.featuredAlbums).then(albums => {
|
||||||
qobuzissimes = albums;
|
qobuzissimes = albums;
|
||||||
loadingQobuzissimes = false;
|
loadingQobuzissimes = false;
|
||||||
if (albums.length > 0) markSectionReady();
|
markSectionFinished();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
loadingQobuzissimes = false;
|
loadingQobuzissimes = false;
|
||||||
@@ -332,47 +357,54 @@
|
|||||||
fetchFeaturedAlbums('editor-picks', LIMITS.featuredAlbums).then(albums => {
|
fetchFeaturedAlbums('editor-picks', LIMITS.featuredAlbums).then(albums => {
|
||||||
editorPicks = albums;
|
editorPicks = albums;
|
||||||
loadingEditorPicks = false;
|
loadingEditorPicks = false;
|
||||||
if (albums.length > 0) markSectionReady();
|
markSectionFinished();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
loadingEditorPicks = false;
|
loadingEditorPicks = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// ML-based scoring for personalized recommendations (falls back to simple queries if no scores)
|
// Wait for ML seeds (local data)
|
||||||
const seeds = await invoke<HomeSeeds>('reco_get_home_ml', {
|
const seeds = await mlPromise;
|
||||||
limitRecentAlbums: LIMITS.recentAlbums,
|
|
||||||
limitContinueTracks: LIMITS.continueTracks,
|
|
||||||
limitTopArtists: LIMITS.topArtists,
|
|
||||||
limitFavorites: Math.max(LIMITS.favoriteAlbums, LIMITS.favoriteTracks)
|
|
||||||
});
|
|
||||||
|
|
||||||
// Seeds are ready, can start showing content
|
// Load ML-based sections in parallel
|
||||||
isInitializing = false;
|
// Continue Listening (tracks)
|
||||||
|
if (isSectionVisible('continueTracks')) {
|
||||||
// Load each section in parallel for progressive rendering
|
fetchTracks(seeds.continueListeningTrackIds).then(tracks => {
|
||||||
const continueTracksPromise = fetchTracks(seeds.continueListeningTrackIds).then(tracks => {
|
|
||||||
continueTracks = tracks;
|
continueTracks = tracks;
|
||||||
loadingContinueTracks = false;
|
loadingContinueTracks = false;
|
||||||
if (tracks.length > 0) markSectionReady();
|
markSectionFinished();
|
||||||
return tracks;
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
// Start recent albums immediately
|
loadingContinueTracks = false;
|
||||||
let recentAlbumIds = normalizeAlbumIds(seeds.recentlyPlayedAlbumIds);
|
|
||||||
if (recentAlbumIds.length === 0) {
|
|
||||||
// Wait for continue tracks to derive album IDs
|
|
||||||
const tracks = await continueTracksPromise;
|
|
||||||
recentAlbumIds = normalizeAlbumIds(tracks.map(track => track.albumId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recently Played (albums) - start immediately with seeds
|
||||||
|
if (isSectionVisible('recentAlbums')) {
|
||||||
|
const recentAlbumIds = normalizeAlbumIds(seeds.recentlyPlayedAlbumIds);
|
||||||
fetchAlbums(recentAlbumIds.slice(0, LIMITS.recentAlbums)).then(albums => {
|
fetchAlbums(recentAlbumIds.slice(0, LIMITS.recentAlbums)).then(albums => {
|
||||||
recentAlbums = albums;
|
recentAlbums = albums;
|
||||||
loadingRecentAlbums = false;
|
loadingRecentAlbums = false;
|
||||||
if (albums.length > 0) markSectionReady();
|
markSectionFinished();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
loadingRecentAlbums = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Favorite albums
|
// Top Artists
|
||||||
|
if (isSectionVisible('topArtists')) {
|
||||||
|
fetchArtists(seeds.topArtistIds.slice(0, LIMITS.topArtists)).then(artists => {
|
||||||
|
topArtists = artists;
|
||||||
|
loadingTopArtists = false;
|
||||||
|
markSectionFinished();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
loadingTopArtists = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Favorite Albums
|
||||||
|
if (isSectionVisible('favoriteAlbums')) {
|
||||||
|
// Get favorite track details to extract album IDs
|
||||||
fetchTracks(seeds.favoriteTrackIds.slice(0, LIMITS.favoriteTracks)).then(async favoriteTrackDetails => {
|
fetchTracks(seeds.favoriteTrackIds.slice(0, LIMITS.favoriteTracks)).then(async favoriteTrackDetails => {
|
||||||
const favoriteAlbumIds = normalizeAlbumIds([
|
const favoriteAlbumIds = normalizeAlbumIds([
|
||||||
...seeds.favoriteAlbumIds,
|
...seeds.favoriteAlbumIds,
|
||||||
@@ -381,20 +413,11 @@
|
|||||||
const albums = await fetchAlbums(favoriteAlbumIds.slice(0, LIMITS.favoriteAlbums));
|
const albums = await fetchAlbums(favoriteAlbumIds.slice(0, LIMITS.favoriteAlbums));
|
||||||
favoriteAlbums = albums;
|
favoriteAlbums = albums;
|
||||||
loadingFavoriteAlbums = false;
|
loadingFavoriteAlbums = false;
|
||||||
if (albums.length > 0) markSectionReady();
|
markSectionFinished();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
// Top artists
|
loadingFavoriteAlbums = false;
|
||||||
let artistSeeds = seeds.topArtistIds;
|
|
||||||
if (artistSeeds.length === 0) {
|
|
||||||
const tracks = await continueTracksPromise;
|
|
||||||
artistSeeds = buildTopArtistSeedsFromTracks(tracks);
|
|
||||||
}
|
}
|
||||||
fetchArtists(artistSeeds.slice(0, LIMITS.topArtists)).then(artists => {
|
|
||||||
topArtists = artists;
|
|
||||||
loadingTopArtists = false;
|
|
||||||
if (artists.length > 0) markSectionReady();
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load home data:', err);
|
console.error('Failed to load home data:', err);
|
||||||
@@ -410,9 +433,9 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="home-view">
|
<div class="home-view">
|
||||||
<!-- Loading Overlay - fades out when content is ready -->
|
<!-- Loading Overlay - fades out when ALL sections are ready -->
|
||||||
{#if isOverlayVisible}
|
{#if isOverlayVisible}
|
||||||
<div class="loading-overlay" class:fade-out={!isInitializing && sectionsReady >= MIN_SECTIONS_BEFORE_SHOW}>
|
<div class="loading-overlay" class:fade-out={sectionsFinished >= totalVisibleSections && totalVisibleSections > 0}>
|
||||||
<div class="loading-content">
|
<div class="loading-content">
|
||||||
<div class="loading-icon">
|
<div class="loading-icon">
|
||||||
<Loader2 size={36} class="spinner" />
|
<Loader2 size={36} class="spinner" />
|
||||||
@@ -571,6 +594,10 @@
|
|||||||
quality={getTrackQuality(track)}
|
quality={getTrackQuality(track)}
|
||||||
hideDownload={true}
|
hideDownload={true}
|
||||||
onPlay={() => onTrackPlay?.(track)}
|
onPlay={() => onTrackPlay?.(track)}
|
||||||
|
menuActions={{
|
||||||
|
onPlayNow: () => onTrackPlay?.(track),
|
||||||
|
onAddFavorite: () => handleAddToFavorites(track.id)
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user