'use client'; import { ScrollArea, ScrollBar } from '../components/ui/scroll-area'; import { Separator } from '../components/ui/separator'; import { Tabs, TabsContent } from '../components/ui/tabs'; import { AlbumArtwork } from './components/album-artwork'; import { useNavidrome } from './components/NavidromeContext'; import { useEffect, useState } from 'react'; import { Album } from '@/lib/navidrome'; import { useNavidromeConfig } from './components/NavidromeConfigContext'; type TimeOfDay = 'morning' | 'afternoon' | 'evening'; export default function MusicPage() { 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) { // Split albums into recent and newest for display const recent = albums.slice(0, Math.ceil(albums.length / 2)); const newest = albums.slice(Math.ceil(albums.length / 2)); setRecentAlbums(recent); setNewestAlbums(newest); } }, [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'; let timeOfDay: TimeOfDay; if (hour >= 5 && hour < 12) { timeOfDay = 'morning'; } else if (hour >= 12 && hour < 18) { timeOfDay = 'afternoon'; } else { timeOfDay = 'evening'; } // Try to get user name from navidrome context, fallback to 'user' let userName = ''; // If you add user info to NavidromeContext, update this logic const { config } = useNavidromeConfig(); if (config && config.username) { userName = config.username; } return (

{greeting}{userName ? `, ${userName}` : ''}!

<>

Recently Played

Albums you've listened to recently.

{isLoading ? ( // Loading skeletons Array.from({ length: 6 }).map((_, i) => (
)) ) : ( recentAlbums.map((album) => ( )) )}
{/* 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

Albums from your music collection.

{isLoading ? ( // Loading skeletons Array.from({ length: 10 }).map((_, i) => (
)) ) : ( newestAlbums.map((album) => ( )) )}
); }