'use client'; import { useState, useEffect } from 'react'; import { cn } from "@/lib/utils"; import { usePathname } from 'next/navigation'; import { Button } from "../../components/ui/button"; import { ScrollArea } from "../../components/ui/scroll-area"; import Link from "next/link"; import Image from "next/image"; import { Playlist } from "@/lib/navidrome"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { useNavidrome } from "./NavidromeContext"; import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger, } from "@/components/ui/context-menu"; interface SidebarProps extends React.HTMLAttributes { playlists: Playlist[]; collapsed?: boolean; onToggle?: () => void; visible?: boolean; favoriteAlbums?: Array<{id: string, name: string, artist: string, coverArt?: string}>; onRemoveFavoriteAlbum?: (albumId: string) => void; } export function Sidebar({ className, playlists, collapsed = false, onToggle, visible = true, favoriteAlbums = [], onRemoveFavoriteAlbum }: SidebarProps) { const pathname = usePathname(); const { api } = useNavidrome(); if (!visible) { return null; } // Define all routes and their active states const routes = { isRoot: pathname === "/", isBrowse: pathname === "/browse", isSearch: pathname === "/search", isQueue: pathname === "/queue", isRadio: pathname === "/radio", isPlaylists: pathname === "/library/playlists", isSongs: pathname === "/library/songs", isArtists: pathname === "/library/artists", isAlbums: pathname === "/library/albums", isHistory: pathname === "/history", isFavorites: pathname === "/favorites", isSettings: pathname === "/settings", // Handle dynamic routes isAlbumPage: pathname.startsWith("/album/"), isArtistPage: pathname.startsWith("/artist/"), isPlaylistPage: pathname.startsWith("/playlist/"), isNewPage: pathname === "/new", }; // Helper function to determine if any sidebar route is active // This prevents highlights on pages not defined in sidebar const isAnySidebarRouteActive = Object.values(routes).some(Boolean); return (

Navigation

{/* Search */} {/* Home */} {/* Queue */} {/* Radio */} {/* Artists */} {/* Albums */} {/* Playlists */} {/* Favorites */}

Library

{/* Browse */} {/* Songs */} {/* History */} {/* Favorite Albums Section */} {favoriteAlbums.length > 0 && ( <>
{favoriteAlbums.slice(0, 5).map((album) => ( { e.preventDefault(); e.stopPropagation(); onRemoveFavoriteAlbum?.(album.id); }} className="text-destructive focus:text-destructive" > Remove from favorites ))} )} {/* Playlists Section */} {playlists.length > 0 && ( <>
{playlists.slice(0, 5).map((playlist) => { const playlistImageUrl = playlist.coverArt && api ? api.getCoverArtUrl(playlist.coverArt, 32) : '/play.png'; // fallback to a music icon return ( ); })} )}
); }