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 { photosSectionPath } from './shared'; import { usePhotosAccountActions, usePhotosAccounts, usePhotosHealth } from './usePhotosData'; // Which Immich library you are looking at, and how to change it. // // The subtitle under "Photos" was already the connection state, so the switcher lives there rather than // adding a second control saying nearly the same thing. With one account it is exactly what it was: a line // of text plus a way into the settings screen. // // Switching invalidates the whole ['photos'] key, because it changes the answer to every query in the // workspace without changing any of their inputs — the grid, the albums, the map are all the other library's // now. Anything less and the previous account's thumbnails stay on screen. export const AccountSwitcher = () => { const { data } = usePhotosAccounts(); const { data: health } = usePhotosHealth(); const { activate } = usePhotosAccountActions(); const accounts = data?.accounts ?? []; const active = accounts.find((account) => account.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.version ?? 'connected') : 'not connected'); if (accounts.length < 2) { return ( {status} ); } return ( {status} {activate.isPending ? ( ) : ( )} Immich accounts {accounts.map((account) => ( void activate.mutateAsync(account.id).catch(() => undefined)} className="gap-2" > {account.label} {account.url} ))} Manage accounts ); };