import { Link } from 'react-router';
import { Check, ChevronsUpDown, Loader2, Settings2 } from 'lucide-react';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { jellyfinSectionPath } from './shared';
import { useJellyfinHealth, useJellyfinServerActions, useJellyfinServers } from './useJellyfinData';
// Which Jellyfin you are looking at, and how to change it.
//
// This machine really does run several instances, so the switcher is not hypothetical — but only the video
// one is expected here; the album and DJ-set instances are the music player's business, and the sidecar
// already drops music libraries from every listing.
//
// Switching invalidates the whole ['jellyfin'] key, because it changes the answer to every query in the
// workspace without changing any of their inputs. Anything less and the previous server's posters stay up.
export const ServerSwitcher = () => {
const { data } = useJellyfinServers();
const { data: health } = useJellyfinHealth();
const { activate } = useJellyfinServerActions();
const servers = data?.servers ?? [];
const active = servers.find((server) => server.isActive) ?? null;
// Before the registry answers, fall back to health — it is the query that was already driving this line.
const status = active?.label ?? (health?.ok ? (health.serverName ?? 'connected') : 'not connected');
if (servers.length < 2) {
return (
{status}
);
}
return (
{status}
{activate.isPending ? (
) : (
)}
Jellyfin servers
{servers.map((server) => (
void activate.mutateAsync(server.id).catch(() => undefined)}
className="gap-2"
>
{server.label}{server.url}
))}
Manage servers
);
};