'use client'; import Image from "next/image" import { PlusCircledIcon } from "@radix-ui/react-icons" import { useRouter } from 'next/navigation'; import { cn } from "@/lib/utils" import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, } from "../../components/ui/context-menu" import { useNavidrome } from "./NavidromeContext" import Link from "next/link"; import { useAudioPlayer, Track } from "@/app/components/AudioPlayerContext"; import { getNavidromeAPI } from "@/lib/navidrome"; import React, { useState, useEffect } from 'react'; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { ArtistIcon } from "@/app/components/artist-icon"; import { Heart, Music, Disc, Mic, Play } from "lucide-react"; import { Album, Artist, Song } from "@/lib/navidrome"; interface AlbumArtworkProps extends React.HTMLAttributes { album: Album aspectRatio?: "portrait" | "square" width?: number height?: number } export function AlbumArtwork({ album, aspectRatio = "portrait", width, height, className, ...props }: AlbumArtworkProps) { const { api, isConnected } = useNavidrome(); const router = useRouter(); const { addAlbumToQueue, playTrack, addToQueue } = useAudioPlayer(); const { playlists, starItem, unstarItem } = useNavidrome(); const handleClick = () => { router.push(`/album/${album.id}`); }; const handleAddToQueue = () => { addAlbumToQueue(album.id); }; const handleStar = () => { if (album.starred) { unstarItem(album.id, 'album'); } else { starItem(album.id, 'album'); } }; const handlePlayAlbum = async (album: Album) => { if (!api) return; try { const songs = await api.getAlbumSongs(album.id); if (songs.length > 0) { const tracks = songs.map((song: Song) => ({ id: song.id, name: song.title, artist: song.artist, album: song.album, albumId: song.albumId, artistId: song.artistId, url: api.getStreamUrl(song.id), duration: song.duration, coverArt: song.coverArt ? api.getCoverArtUrl(song.coverArt) : undefined, starred: !!song.starred })); playTrack(tracks[0]); tracks.slice(1).forEach((track: Track) => addToQueue(track)); } } catch (error) { console.error('Failed to play album:', error); } }; const toggleFavorite = async (id: string, type: 'song' | 'album' | 'artist', isStarred: boolean) => { if (!api) return; try { if (isStarred) { await api.unstar(id, type); } else { await api.star(id, type); } } catch (error) { console.error('Failed to toggle favorite:', error); } }; // Get cover art URL with proper fallback const coverArtUrl = album.coverArt && api ? api.getCoverArtUrl(album.coverArt, 300) : '/default-user.jpg'; return (
handleClick()}>
{album.coverArt && api ? ( {album.name} ) : (
)}
handlePlayAlbum(album)}/>

{album.name}

router.push(album.artistId)}>{album.artist}

{album.songCount} songs • {Math.floor(album.duration / 60)} min

{/*
{album.name}
*/}
{album.starred ? 'Remove from Favorites' : 'Add to Favorites'} Add to Playlist New Playlist {playlists.map((playlist) => ( {playlist.name} ))} Add Album to Queue Play Next Play Later {album.starred ? '★ Starred' : '☆ Star'} Share
) }