diff --git a/web/src/components/AppSidebar.test.tsx b/web/src/components/AppSidebar.test.tsx index e6574e93..964d9e13 100644 --- a/web/src/components/AppSidebar.test.tsx +++ b/web/src/components/AppSidebar.test.tsx @@ -1,3 +1,5 @@ +// @vitest-environment node + import type { ReactNode } from "react"; import { renderToStaticMarkup } from "react-dom/server"; import { MemoryRouter, Route, Routes } from "react-router"; @@ -47,6 +49,12 @@ vi.mock("@/hooks/queries/pluginSettings", () => ({ }), })); +vi.mock("@/hooks/queries/useRequests", () => ({ + useRequestFeatureStatus: () => ({ + data: { requests_enabled: false }, + }), +})); + vi.mock("@/hooks/useViewTransition", () => ({ useViewTransitionNavigate: () => vi.fn(), })); @@ -133,6 +141,12 @@ describe("AppSidebar", () => { expect(markup).not.toContain("text-sidebar-primary-foreground bg-sidebar-accent"); }); + it("preserves the current library query when linking to the active library", () => { + const markup = renderSidebar("/library/7?tab=library&sort=year&order=desc"); + + expect(markup).toContain('href="/library/7?tab=library&sort=year&order=desc"'); + }); + it("keeps collapsed navigation rows left-anchored instead of centering icons", () => { const markup = renderSidebar("/item/42", { collapsed: true }); diff --git a/web/src/components/AppSidebar.tsx b/web/src/components/AppSidebar.tsx index 0edf170b..42cd283f 100644 --- a/web/src/components/AppSidebar.tsx +++ b/web/src/components/AppSidebar.tsx @@ -68,6 +68,13 @@ function getLibraryIcon(type: string) { } } +function getLibraryIdFromPathname(pathname: string): number | null { + const match = pathname.match(/^\/library\/(\d+)(?:\/|$)/); + if (!match) return null; + const id = Number(match[1]); + return Number.isInteger(id) && id > 0 ? id : null; +} + function SidebarLabel({ children, show }: { children: ReactNode; show: boolean }) { return ( {libraries.map((lib) => { - const href = `/library/${lib.id}`; + const baseHref = `/library/${lib.id}`; const active = activeLibraryId === lib.id; + const href = + active && location.pathname === baseHref + ? `${baseHref}${location.search}` + : baseHref; const libraryPins = pins[String(lib.id)] ?? []; const hasPins = libraryPins.length > 0; const isExpanded = hasPins && !expandedLibraries.has(lib.id);