'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, Album } from "@/lib/navidrome"; import { Search, Home, List, Radio, Users, Disc, Music, Heart, Grid3X3, Clock, Settings, Circle } from "lucide-react"; import { useNavidrome } from "./NavidromeContext"; import { useRecentlyPlayedAlbums } from "@/hooks/use-recently-played-albums"; import { useSidebarShortcuts } from "@/hooks/use-sidebar-shortcuts"; import { useSidebarLayout, SidebarItem } from "@/hooks/use-sidebar-layout"; import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger, } from "@/components/ui/context-menu"; // Icon mapping for sidebar items const iconMap: Record = { search: , home: , queue: , radio: , artists: , albums: , playlists: , favorites: , browse: , songs: , history: , settings: , }; interface SidebarProps extends React.HTMLAttributes { playlists: Playlist[]; visible?: boolean; favoriteAlbums?: Array<{id: string, name: string, artist: string, coverArt?: string}>; onRemoveFavoriteAlbum?: (albumId: string) => void; } export function Sidebar({ className, playlists, visible = true, favoriteAlbums = [], onRemoveFavoriteAlbum }: SidebarProps) { const pathname = usePathname(); const { api } = useNavidrome(); const { recentAlbums } = useRecentlyPlayedAlbums(); const { shortcutType } = useSidebarShortcuts(); const { settings } = useSidebarLayout(); if (!visible) { return null; } // Check if a route is active const isRouteActive = (href: string): boolean => { if (href === '/') return pathname === '/'; return pathname.startsWith(href); }; // Get visible navigation items const visibleItems = settings.items.filter(item => item.visible); return (
{/* Main Navigation Items */} {visibleItems.map((item) => ( ))} {/* Dynamic Shortcuts Section */} {(shortcutType === 'albums' || shortcutType === 'both') && 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 ))} )} {/* Recently Played Albums */} {(shortcutType === 'albums' || shortcutType === 'both') && recentAlbums.length > 0 && ( <>
{recentAlbums.slice(0, 5).map((album) => ( ))} )} {/* Playlists Section */} {(shortcutType === 'playlists' || shortcutType === 'both') && playlists.length > 0 && ( <>
{playlists.slice(0, 5).map((playlist) => ( ))} )}
); }