import type { JellyItem } from './shared'; import { Link, NavLink, useSearchParams } from 'react-router'; import { Clapperboard, Film, FolderOpen, Home, Images, ListVideo, Plug, Search, Tv } from 'lucide-react'; import { jellyfinSectionPath, VIEW_PARAM } from './shared'; import { ServerSwitcher } from './ServerSwitcher'; import { useJellyfinViews } from './useJellyfinData'; // Left panel of the /jellyfin workspace: Home and Search, the libraries the server actually has, then the // connection screen. // // The libraries are not a fixed vocabulary, so they cannot be sections in the path — they are // /jellyfin/library?view=. That keeps the section list closed (four entries, checked by a type guard) // while the thing being browsed stays addressable, which is the same split the photos app uses for albums. // // Their active state is computed rather than taken from NavLink, because every library link shares the path // /jellyfin/library and react-router's isActive does not look at the query string. const ICON_FOR_COLLECTION: Record = { movies: Film, tvshows: Tv, homevideos: Images, musicvideos: Clapperboard, boxsets: FolderOpen, playlists: ListVideo, }; const ROW = 'group relative flex items-center gap-3 rounded-lg px-3 py-2 text-left text-sm transition-colors'; const ACTIVE = 'bg-primary/10 font-medium text-primary'; const IDLE = 'text-muted-foreground hover:bg-muted hover:text-foreground'; const Marker = () => ; export const JellyfinNav = () => { const { data } = useJellyfinViews(); const [params] = useSearchParams(); const activeView = params.get(VIEW_PARAM); const views = data?.views ?? []; const sectionLink = (id: 'home' | 'search' | 'settings', label: string, Icon: typeof Film) => ( `${ROW} ${isActive ? ACTIVE : IDLE}`}> {({ isActive }) => ( <> {isActive && } {label} )} ); const libraryLink = (view: JellyItem) => { const Icon = ICON_FOR_COLLECTION[view.CollectionType ?? ''] ?? FolderOpen; const isActive = activeView === view.Id; return ( {isActive && } {view.Name ?? 'Library'} ); }; return (
Video
{views.length > 0 && ( <>

Libraries

)}
); };