From f9dfae70d40f36448f75ed747e7aed28c3aafa9f Mon Sep 17 00:00:00 2001 From: angel Date: Wed, 2 Jul 2025 16:49:10 +0000 Subject: [PATCH] feat: add favorite albums section with loading state in MusicPage --- app/page.tsx | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/app/page.tsx b/app/page.tsx index e2515a4..4181622 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -11,9 +11,11 @@ import { useNavidromeConfig } from './components/NavidromeConfigContext'; type TimeOfDay = 'morning' | 'afternoon' | 'evening'; export default function MusicPage() { - const { albums, isLoading } = useNavidrome(); + const { albums, isLoading, api, isConnected } = useNavidrome(); const [recentAlbums, setRecentAlbums] = useState([]); const [newestAlbums, setNewestAlbums] = useState([]); + const [favoriteAlbums, setFavoriteAlbums] = useState([]); + const [favoritesLoading, setFavoritesLoading] = useState(true); useEffect(() => { if (albums.length > 0) { @@ -25,6 +27,24 @@ export default function MusicPage() { } }, [albums]); + useEffect(() => { + const loadFavoriteAlbums = async () => { + if (!api || !isConnected) return; + + setFavoritesLoading(true); + try { + const starredAlbums = await api.getAlbums('starred', 20); // Limit to 20 for homepage + setFavoriteAlbums(starredAlbums); + } catch (error) { + console.error('Failed to load favorite albums:', error); + } finally { + setFavoritesLoading(false); + } + }; + + loadFavoriteAlbums(); + }, [api, isConnected]); + // Get greeting and time of day const hour = new Date().getHours(); const greeting = hour < 12 ? 'Good morning' : 'Good afternoon'; @@ -106,6 +126,46 @@ export default function MusicPage() { + + {/* Favorite Albums Section */} + {favoriteAlbums.length > 0 && ( + <> +
+

+ Favorite Albums +

+

+ Your starred albums collection. +

+
+ +
+ +
+ {favoritesLoading ? ( + // Loading skeletons + Array.from({ length: 6 }).map((_, i) => ( +
+ )) + ) : ( + favoriteAlbums.map((album) => ( + + )) + )} +
+ + +
+ + )} +

Your Library