Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
Port app shell and sidebar to shadcn (EVE-308) (#751)
Carter Smith0788e933dc6a
diff --git a/src/client/components/DefaultCatchBoundary.tsx b/src/client/components/DefaultCatchBoundary.tsxindex 4778e61a..8faae445 100644--- a/src/client/components/DefaultCatchBoundary.tsx+++ b/src/client/components/DefaultCatchBoundary.tsx@@ -8,6 +8,8 @@ import {} from "@/client/lib/error-messages";import { AuthErrorCard } from "@/client/components/AuthErrorCard";import { captureClientError } from "@/client/lib/posthog";+import { Button } from "@/client/components/ui/button";+import { Card, CardContent, CardFooter } from "@/client/components/ui/card";export function DefaultCatchBoundary({ error }: ErrorComponentProps) {const router = useRouter();@@ -35,34 +37,49 @@ export function DefaultCatchBoundary({ error }: ErrorComponentProps) {}, [error, errorCode, pathname]);const genericError = (- <div className="min-w-0 flex-1 p-4 flex flex-col items-center justify-center gap-6">- <p className="text-center text-error">{message}</p>- <div className="flex gap-2 items-center flex-wrap">- <button- onClick={() => {- void router.invalidate();- }}- className="btn btn-primary btn-sm"- >- Try Again- </button>- {isRoot ? (- <Link to="/" className="btn btn-sm">- Home- </Link>- ) : (- <Link- to="/"- className="btn btn-sm"- onClick={(e) => {- e.preventDefault();- window.history.back();+ <div className="flex min-w-0 flex-1 items-center justify-center p-4">+ <Card className="w-full max-w-md">+ <CardContent className="text-center text-destructive">+ {message}+ </CardContent>+ <CardFooter className="flex flex-wrap justify-center gap-2">+ <Button+ onClick={() => {+ void router.invalidate();}}+ size="sm">- Go Back- </Link>- )}- </div>+ Try Again+ </Button>+ {isRoot ? (+ <Button+ nativeButton={false}+ render={<Link to="/" />}+ size="sm"+ variant="outline"+ >+ Home+ </Button>+ ) : (+ <Button+ nativeButton={false}+ render={+ <Link+ to="/"+ onClick={(e) => {+ e.preventDefault();+ window.history.back();+ }}+ />+ }+ size="sm"+ variant="outline"+ >+ Go Back+ </Button>+ )}+ </CardFooter>+ </Card></div>);diff --git a/src/client/components/NotFound.tsx b/src/client/components/NotFound.tsxindex 24509a0a..a9db93e5 100644--- a/src/client/components/NotFound.tsx+++ b/src/client/components/NotFound.tsx@@ -1,10 +1,29 @@+import { Link } from "@tanstack/react-router";+import { Button } from "@/client/components/ui/button";+import {+ Card,+ CardContent,+ CardFooter,+ CardHeader,+ CardTitle,+} from "@/client/components/ui/card";+export function NotFound() {return (- <div className="space-y-2 p-4">- <h1 className="text-2xl">404</h1>- <p className="text-base-content/70">- The page you are looking for does not exist.- </p>+ <div className="flex min-h-full items-center justify-center p-4">+ <Card className="w-full max-w-md">+ <CardHeader>+ <CardTitle>404</CardTitle>+ </CardHeader>+ <CardContent className="text-muted-foreground">+ The page you are looking for does not exist.+ </CardContent>+ <CardFooter>+ <Button nativeButton={false} render={<Link to="/" />}>+ Home+ </Button>+ </CardFooter>+ </Card></div>);}diff --git a/src/client/components/Sidebar.tsx b/src/client/components/Sidebar.tsxindex b88c5c40..8fd3b039 100644--- a/src/client/components/Sidebar.tsx+++ b/src/client/components/Sidebar.tsx@@ -13,7 +13,6 @@ import {MessageCircle,Settings,User,- X,} from "lucide-react";import { organizationContextQueryOptions } from "@/client/features/team/organizationQueries";import { switchOrganization } from "@/serverFunctions/organization";@@ -23,99 +22,100 @@ import {} from "@/client/navigation/items";import { ProjectSwitcher } from "@/client/features/projects/ProjectSwitcher";import { SamSidebarPanel } from "@/client/features/sam/SamSidebarPanel";-import { ThemePreferenceMenuItems } from "@/client/components/ThemePreferenceMenuItems";-import { closeDropdown } from "@/client/lib/dropdown";+import { ThemePreferenceRadio } from "@/client/components/ThemePreferenceMenuItems";import { getStandardErrorMessage } from "@/client/lib/error-messages";import { signOutAndRedirect, useSession } from "@/lib/auth-client";import { BILLING_ROUTE } from "@/shared/billing";+import {+ Sidebar as UiSidebar,+ SidebarContent,+ SidebarFooter as UiSidebarFooter,+ SidebarGroup,+ SidebarGroupContent,+ SidebarGroupLabel,+ SidebarHeader,+ SidebarMenu,+ SidebarMenuButton,+ SidebarMenuItem,+ useSidebar,+} from "@/client/components/ui/sidebar";+import { Tabs, TabsList, TabsTrigger } from "@/client/components/ui/tabs";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuGroup,+ DropdownMenuItem,+ DropdownMenuLabel,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from "@/client/components/ui/dropdown-menu";-interface SidebarProps {- projectId: string | null;- onNavigate?: () => void;- onClose?: () => void;-}--const navItemBaseClass =- "relative flex items-center gap-2.5 rounded-md px-3 py-1.5 text-sm text-base-content/70";--// Hover uses a lighter tint than the active background (bg-sidebar-accent) so a-// hovered item next to the active one stays visually distinct instead of-// merging into a single block.-const navItemClass = `${navItemBaseClass} transition-colors hover:bg-sidebar-accent/50 hover:text-base-content`;--const navItemActiveProps = {- // Keep the active tint on hover so the active item does not fall back to the- // lighter hover background of navItemClass.- className:- "bg-sidebar-accent hover:bg-sidebar-accent font-medium text-base-content",-};+const navButtonClass =+ "relative text-sidebar-foreground/70 hover:bg-sidebar-accent/50 hover:text-sidebar-foreground data-active:bg-sidebar-accent data-active:text-sidebar-accent-foreground data-active:before:absolute data-active:before:inset-y-1 data-active:before:left-0 data-active:before:w-[3px] data-active:before:rounded-r-full data-active:before:bg-primary";function SidebarNavLink({icon: Icon,label,- onNavigate,linkProps,}: {icon: ComponentType<{ className?: string }>;label: string;- onNavigate?: () => void;linkProps: LinkOptions;}) {+ const { setOpenMobile } = useSidebar();return (- <Link- onClick={onNavigate}- activeOptions={{ exact: false, includeSearch: false }}- {...linkProps}- className={navItemClass}- activeProps={navItemActiveProps}- >- {({ isActive }: { isActive: boolean }) => (- <>- {isActive ? (- <div className="absolute left-0 top-1 bottom-1 w-[3px] rounded-r-full bg-primary" />- ) : null}- <Icon className="h-4 w-4 shrink-0" />- <span className="truncate">{label}</span>- </>- )}- </Link>+ <SidebarMenuItem>+ <Link+ {...linkProps}+ activeOptions={{+ exact: false,+ includeSearch: false,+ ...linkProps.activeOptions,+ }}+ onClick={() => setOpenMobile(false)}+ >+ {({ isActive }) => (+ <SidebarMenuButton+ render={<span />}+ isActive={isActive}+ className={navButtonClass}+ >+ <Icon className="size-4" />+ <span>{label}</span>+ </SidebarMenuButton>+ )}+ </Link>+ </SidebarMenuItem>);}-export function Sidebar({ projectId, onNavigate, onClose }: SidebarProps) {+export function Sidebar({ projectId }: { projectId: string | null }) {const navGroups = projectId? getProjectNavGroups(projectId): [connectNavGroup];const navigate = useNavigate();- const location = useLocation();- const onSamRoute = location.pathname.includes("/sam");-- // PostHog-style sidebar tabs: Browse shows the regular nav, Chat shows the- // SAM chat history. The tab is view state (switching to Browse leaves the- // conversation open in the content panel), but the route wins: landing on- // /sam selects Chat, navigating anywhere else flips back to Browse.+ const { pathname } = useLocation();+ const { setOpenMobile } = useSidebar();+ const onSamRoute = pathname.includes("/sam");const [view, setView] = useState<"browse" | "chat">(onSamRoute ? "chat" : "browse",);+useEffect(() => {setView(onSamRoute ? "chat" : "browse");}, [onSamRoute]);- // Both tabs only render with a project selected, so they receive its id.const openChat = (activeProjectId: string) => {setView("chat");- if (!onSamRoute) {- void navigate({- to: "/p/$projectId/sam",- params: { projectId: activeProjectId },- search: {},- });- onNavigate?.();- }+ if (onSamRoute) return;+ void navigate({+ to: "/p/$projectId/sam",+ params: { projectId: activeProjectId },+ search: {},+ });+ setOpenMobile(false);};- // Coming back from Chat, land on the dashboard rather than leaving the- // conversation filling the content panel next to a Browse nav.const openBrowse = (activeProjectId: string) => {setView("browse");if (!onSamRoute) return;@@ -123,121 +123,89 @@ export function Sidebar({ projectId, onNavigate, onClose }: SidebarProps) {to: "/p/$projectId",params: { projectId: activeProjectId },});- onNavigate?.();+ setOpenMobile(false);};return (- <div className="flex h-full w-60 flex-col bg-sidebar">- <div className="flex items-center justify-between px-4 pb-2 pt-3">+ <UiSidebar variant="inset" collapsible="offcanvas" className="md:!p-0">+ <SidebarHeader className="gap-0 px-3 pb-1 pt-3"><Linkto="/"- onClick={onNavigate}- className="text-base font-semibold text-base-content"+ onClick={() => setOpenMobile(false)}+ className="px-1 pb-2 text-base font-semibold text-sidebar-foreground">OpenSEO</Link>- {onClose ? (- <button- type="button"- onClick={onClose}- className="btn btn-ghost btn-sm btn-circle"- aria-label="Close sidebar"- >- <X className="h-5 w-5" />- </button>- ) : null}- </div>-- <div className="px-3 pb-1"><ProjectSwitcheractiveProjectId={projectId}- onCloseDrawer={onNavigate}+ onCloseDrawer={() => setOpenMobile(false)}/>- </div>-- {projectId ? (- // Same underline tab idiom as the in-page tab strips (e.g. Domain- // Overview's Top Keywords / Top Pages).- <div className="px-3 pb-1">- <div role="tablist" className="tabs tabs-border w-full">- <SidebarViewTab- icon={LayoutGrid}- label="Browse"- active={view === "browse"}- onClick={() => openBrowse(projectId)}- />- <SidebarViewTab- icon={MessageCircle}- label="Chat"- active={view === "chat"}- onClick={() => openChat(projectId)}- />- </div>- </div>- ) : null}-- {view === "chat" && projectId ? (- <SamSidebarPanel projectId={projectId} onNavigate={onNavigate} />- ) : (- <nav className="min-h-0 flex-1 overflow-y-auto px-2 py-2">- {navGroups.map((group) => (- <div key={group.label} className="mb-1">- <div className="px-3 pb-1 pt-3 text-xs font-semibold uppercase tracking-wider text-base-content/40">- {group.label}- </div>- {group.items.map((item) => {- const { icon, label, ...linkProps } = item;- return (- <SidebarNavLink- key={linkProps.to}- icon={icon}- label={label}- onNavigate={onNavigate}- linkProps={linkProps}- />- );- })}- </div>- ))}- </nav>- )}-- <SidebarFooter onNavigate={onNavigate} />- </div>- );-}+ {projectId ? (+ <Tabs+ value={view}+ onValueChange={(value) => {+ if (value === "chat") openChat(projectId);+ else openBrowse(projectId);+ }}+ className="pt-2"+ >+ <TabsList variant="line" className="w-full">+ <TabsTrigger value="browse">+ <LayoutGrid className="size-4" />+ Browse+ </TabsTrigger>+ <TabsTrigger value="chat">+ <MessageCircle className="size-4" />+ Chat+ </TabsTrigger>+ </TabsList>+ </Tabs>+ ) : null}+ </SidebarHeader>-function SidebarViewTab({- icon: Icon,- label,- active,- onClick,-}: {- icon: ComponentType<{ className?: string }>;- label: string;- active: boolean;- onClick: () => void;-}) {- return (- <button- type="button"- role="tab"- aria-selected={active}- onClick={onClick}- className={`tab flex-1 gap-1.5 ${active ? "tab-active" : ""}`}- >- <Icon className="size-4" />- {label}- </button>+ <SidebarContent>+ {view === "chat" && projectId ? (+ <SamSidebarPanel+ projectId={projectId}+ onNavigate={() => setOpenMobile(false)}+ />+ ) : (+ <nav aria-label="Main navigation">+ {navGroups.map((group) => (+ <SidebarGroup key={group.label} className="py-1">+ <SidebarGroupLabel className="h-7 uppercase tracking-wider text-sidebar-foreground/40">+ {group.label}+ </SidebarGroupLabel>+ <SidebarGroupContent>+ <SidebarMenu>+ {group.items.map((item) => {+ const { icon, label, ...linkProps } = item;+ return (+ <SidebarNavLink+ key={linkProps.to}+ icon={icon}+ label={label}+ linkProps={linkProps}+ />+ );+ })}+ </SidebarMenu>+ </SidebarGroupContent>+ </SidebarGroup>+ ))}+ </nav>+ )}+ </SidebarContent>+ <AccountFooter />+ </UiSidebar>);}-function SidebarFooter({ onNavigate }: { onNavigate?: () => void }) {+function AccountFooter() {const { data: session } = useSession();- // Only hosted mode has a session, so the account menu below is hosted-only.+ const { setOpenMobile } = useSidebar();const email = session?.user?.email;const [isSwitching, setIsSwitching] = useState(false);-const orgContextQuery = useQuery({...organizationContextQueryOptions(),enabled: Boolean(email),@@ -245,18 +213,11 @@ function SidebarFooter({ onNavigate }: { onNavigate?: () => void }) {const organizations = orgContextQuery.data?.organizations ?? [];const activeOrganizationId = orgContextQuery.data?.organizationId;- const closeMenu = () => {- closeDropdown();- onNavigate?.();- };-async function handleSwitchOrganization(organizationId: string) {if (isSwitching || organizationId === activeOrganizationId) return;setIsSwitching(true);try {await switchOrganization({ data: { organizationId } });- // Full reload: every cached query and the project-scoped URL belong to- // the previous organization.window.location.assign("/");} catch (error) {toast.error(getStandardErrorMessage(error));@@ -265,100 +226,104 @@ function SidebarFooter({ onNavigate }: { onNavigate?: () => void }) {}return (- <div className="shrink-0 border-t border-base-300 px-2 py-2 pb-safe">- <SidebarNavLink- icon={CircleHelp}- label="Help & Community"- onNavigate={onNavigate}- linkProps={{ to: "/support" }}- />-- {email ? (- <div className="dropdown dropdown-top w-full">- <button- type="button"- tabIndex={0}- className={`${navItemClass} w-full`}- aria-label="Open account menu"- >- <User className="h-4 w-4 shrink-0" />- <span className="truncate" data-ph-mask>- {email}- </span>- </button>- <ul- tabIndex={0}- className="dropdown-content z-30 menu mb-1 w-56 rounded-box border border-base-300 bg-base-100 p-2 shadow-lg"- >- {organizations.length > 1 ? (- <>- <li className="menu-title flex flex-row items-center gap-1.5 max-w-full">- <ArrowLeftRight className="h-3 w-3" />- Organization- </li>- {organizations.map((organization) => (- <li key={organization.organizationId}>- <button- type="button"- disabled={isSwitching}- onClick={() =>- void handleSwitchOrganization(- organization.organizationId,- )- }- >- <span className="truncate">- {organization.organizationName}- </span>- {organization.organizationId === activeOrganizationId ? (- <Check className="h-4 w-4 shrink-0" />- ) : null}- </button>- </li>- ))}- <li- aria-hidden- className="pointer-events-none my-1 h-px bg-base-300 p-0"- />- </>- ) : null}- <li>- <Link to="/settings" onClick={closeMenu}>- <Settings className="h-4 w-4" />- Settings- </Link>- </li>- <li>- <Link to={BILLING_ROUTE} onClick={closeMenu}>- <CreditCard className="h-4 w-4" />- Billing- </Link>- </li>- <ThemePreferenceMenuItems />- <li- aria-hidden- className="pointer-events-none my-1 h-px bg-base-300 p-0"- />- <li>- <button- type="button"- className="text-error"- onClick={() => signOutAndRedirect()}- >- <LogOut className="h-4 w-4" />- Sign out- </button>- </li>- </ul>- </div>- ) : (+ <UiSidebarFooter className="gap-0 border-t border-sidebar-border pb-safe">+ <SidebarMenu><SidebarNavLink- icon={Settings}- label="Settings"- onNavigate={onNavigate}- linkProps={{ to: "/settings" }}+ icon={CircleHelp}+ label="Help & Community"+ linkProps={{ to: "/support" }}/>- )}- </div>+ {email ? (+ <SidebarMenuItem>+ <DropdownMenu>+ <DropdownMenuTrigger+ render={+ <SidebarMenuButton+ className={navButtonClass}+ aria-label="Open account menu"+ />+ }+ >+ <User className="size-4" />+ <span className="truncate" data-ph-mask>+ {email}+ </span>+ </DropdownMenuTrigger>+ <DropdownMenuContent side="top" className="w-56">+ {organizations.length > 1 ? (+ <>+ <DropdownMenuGroup>+ <DropdownMenuLabel className="flex items-center gap-1.5">+ <ArrowLeftRight className="size-3" />+ Organization+ </DropdownMenuLabel>+ {organizations.map((organization) => (+ <DropdownMenuItem+ key={organization.organizationId}+ disabled={isSwitching}+ onClick={() =>+ void handleSwitchOrganization(+ organization.organizationId,+ )+ }+ >+ <span className="truncate">+ {organization.organizationName}+ </span>+ {organization.organizationId ===+ activeOrganizationId ? (+ <Check className="ml-auto size-4" />+ ) : null}+ </DropdownMenuItem>+ ))}+ </DropdownMenuGroup>+ <DropdownMenuSeparator />+ </>+ ) : null}+ <DropdownMenuItem+ render={+ <Link to="/settings" onClick={() => setOpenMobile(false)} />+ }+ >+ <Settings className="size-4" />+ Settings+ </DropdownMenuItem>+ <DropdownMenuItem+ render={+ <Link+ to={BILLING_ROUTE}+ onClick={() => setOpenMobile(false)}+ />+ }+ >+ <CreditCard className="size-4" />+ Billing+ </DropdownMenuItem>+ <DropdownMenuGroup>+ <DropdownMenuLabel>Theme</DropdownMenuLabel>+ <div className="px-1 pb-1">+ <ThemePreferenceRadio />+ </div>+ </DropdownMenuGroup>+ <DropdownMenuSeparator />+ <DropdownMenuItem+ variant="destructive"+ onClick={() => signOutAndRedirect()}+ >+ <LogOut className="size-4" />+ Sign out+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </SidebarMenuItem>+ ) : (+ <SidebarNavLink+ icon={Settings}+ label="Settings"+ linkProps={{ to: "/settings" }}+ />+ )}+ </SidebarMenu>+ </UiSidebarFooter>);}diff --git a/src/client/components/ThemePreferenceMenuItems.tsx b/src/client/components/ThemePreferenceMenuItems.tsxindex eb504ab9..b9945c53 100644--- a/src/client/components/ThemePreferenceMenuItems.tsx+++ b/src/client/components/ThemePreferenceMenuItems.tsx@@ -32,20 +32,6 @@ export function ThemePreferenceRadio() {);}-export function ThemePreferenceMenuItems() {- return (- <>- <li className="menu-title pt-2">- <span>Theme</span>- </li>-- <li>- <ThemePreferenceRadio />- </li>- </>- );-}-export function ThemePreferenceDropdownItems() {const { themePreference, setThemePreference } = useThemePreference();diff --git a/src/client/components/ui/sheet.tsx b/src/client/components/ui/sheet.tsxnew file mode 100644index 00000000..7a91417f--- /dev/null+++ b/src/client/components/ui/sheet.tsx@@ -0,0 +1,132 @@+import * as React from "react";+import { Dialog as SheetPrimitive } from "@base-ui/react/dialog";+import { cn } from "cn";++import { Button } from "@/client/components/ui/button";+import { XIcon } from "lucide-react";++function Sheet({ ...props }: SheetPrimitive.Root.Props) {+ return <SheetPrimitive.Root data-slot="sheet" {...props} />;+}++function SheetTrigger({ ...props }: SheetPrimitive.Trigger.Props) {+ return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />;+}++function SheetClose({ ...props }: SheetPrimitive.Close.Props) {+ return <SheetPrimitive.Close data-slot="sheet-close" {...props} />;+}++function SheetPortal({ ...props }: SheetPrimitive.Portal.Props) {+ return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />;+}++function SheetOverlay({ className, ...props }: SheetPrimitive.Backdrop.Props) {+ return (+ <SheetPrimitive.Backdrop+ data-slot="sheet-overlay"+ className={cn(+ "fixed inset-0 z-50 bg-black/10 transition-opacity duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0 supports-backdrop-filter:backdrop-blur-xs",+ className,+ )}+ {...props}+ />+ );+}++function SheetContent({+ className,+ children,+ side = "right",+ showCloseButton = true,+ ...props+}: SheetPrimitive.Popup.Props & {+ side?: "top" | "right" | "bottom" | "left";+ showCloseButton?: boolean;+}) {+ return (+ <SheetPortal>+ <SheetOverlay />+ <SheetPrimitive.Popup+ data-slot="sheet-content"+ data-side={side}+ className={cn(+ "fixed z-50 flex flex-col gap-4 bg-popover bg-clip-padding text-sm text-popover-foreground shadow-lg transition duration-200 ease-in-out data-ending-style:opacity-0 data-starting-style:opacity-0 data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t data-[side=bottom]:data-ending-style:translate-y-[2.5rem] data-[side=bottom]:data-starting-style:translate-y-[2.5rem] data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r data-[side=left]:data-ending-style:translate-x-[-2.5rem] data-[side=left]:data-starting-style:translate-x-[-2.5rem] data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l data-[side=right]:data-ending-style:translate-x-[2.5rem] data-[side=right]:data-starting-style:translate-x-[2.5rem] data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=top]:data-ending-style:translate-y-[-2.5rem] data-[side=top]:data-starting-style:translate-y-[-2.5rem] data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm",+ className,+ )}+ {...props}+ >+ {children}+ {showCloseButton && (+ <SheetPrimitive.Close+ data-slot="sheet-close"+ render={+ <Button+ variant="ghost"+ className="absolute top-3 right-3"+ size="icon-sm"+ />+ }+ >+ <XIcon />+ <span className="sr-only">Close</span>+ </SheetPrimitive.Close>+ )}+ </SheetPrimitive.Popup>+ </SheetPortal>+ );+}++function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="sheet-header"+ className={cn("flex flex-col gap-0.5 p-4", className)}+ {...props}+ />+ );+}++function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="sheet-footer"+ className={cn("mt-auto flex flex-col gap-2 p-4", className)}+ {...props}+ />+ );+}++function SheetTitle({ className, ...props }: SheetPrimitive.Title.Props) {+ return (+ <SheetPrimitive.Title+ data-slot="sheet-title"+ className={cn("text-base font-medium text-foreground", className)}+ {...props}+ />+ );+}++function SheetDescription({+ className,+ ...props+}: SheetPrimitive.Description.Props) {+ return (+ <SheetPrimitive.Description+ data-slot="sheet-description"+ className={cn("text-sm text-muted-foreground", className)}+ {...props}+ />+ );+}++export {+ Sheet,+ SheetTrigger,+ SheetClose,+ SheetContent,+ SheetHeader,+ SheetFooter,+ SheetTitle,+ SheetDescription,+};diff --git a/src/client/components/ui/sidebar.tsx b/src/client/components/ui/sidebar.tsxnew file mode 100644index 00000000..9cea82eb--- /dev/null+++ b/src/client/components/ui/sidebar.tsx@@ -0,0 +1,728 @@+/* eslint-disable max-lines -- stock shadcn Sidebar from the official CLI */+"use client";++import * as React from "react";+import { mergeProps } from "@base-ui/react/merge-props";+import { useRender } from "@base-ui/react/use-render";+import { cva, type VariantProps } from "class-variance-authority";+import { cn } from "cn";++import { useIsMobile } from "@/client/hooks/use-mobile";+import { Button } from "@/client/components/ui/button";+import { Input } from "@/client/components/ui/input";+import { Separator } from "@/client/components/ui/separator";+import {+ Sheet,+ SheetContent,+ SheetDescription,+ SheetHeader,+ SheetTitle,+} from "@/client/components/ui/sheet";+import { Skeleton } from "@/client/components/ui/skeleton";+import {+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from "@/client/components/ui/tooltip";+import { PanelLeftIcon } from "lucide-react";++const SIDEBAR_COOKIE_NAME = "sidebar_state";+const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;+const SIDEBAR_WIDTH = "15rem";+const SIDEBAR_WIDTH_MOBILE = "15rem";+const SIDEBAR_WIDTH_ICON = "3rem";+const SIDEBAR_KEYBOARD_SHORTCUT = "b";++type SidebarContextProps = {+ state: "expanded" | "collapsed";+ open: boolean;+ setOpen: (open: boolean) => void;+ openMobile: boolean;+ setOpenMobile: (open: boolean) => void;+ isMobile: boolean;+ toggleSidebar: () => void;+};++const SidebarContext = React.createContext<SidebarContextProps | null>(null);++function useSidebar() {+ const context = React.useContext(SidebarContext);+ if (!context) {+ throw new Error("useSidebar must be used within a SidebarProvider.");+ }++ return context;+}++function SidebarProvider({+ defaultOpen = true,+ open: openProp,+ onOpenChange: setOpenProp,+ className,+ style,+ children,+ ...props+}: React.ComponentProps<"div"> & {+ defaultOpen?: boolean;+ open?: boolean;+ onOpenChange?: (open: boolean) => void;+}) {+ const isMobile = useIsMobile();+ const [openMobile, setOpenMobile] = React.useState(false);++ // This is the internal state of the sidebar.+ // We use openProp and setOpenProp for control from outside the component.+ const [_open, _setOpen] = React.useState(defaultOpen);+ const open = openProp ?? _open;+ const setOpen = React.useCallback(+ (value: boolean | ((value: boolean) => boolean)) => {+ const openState = typeof value === "function" ? value(open) : value;+ if (setOpenProp) {+ setOpenProp(openState);+ } else {+ _setOpen(openState);+ }++ // This sets the cookie to keep the sidebar state.+ document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;+ },+ [setOpenProp, open],+ );++ // Helper to toggle the sidebar.+ const toggleSidebar = React.useCallback(() => {+ return isMobile+ ? setOpenMobile((current) => !current)+ : setOpen((current) => !current);+ }, [isMobile, setOpen, setOpenMobile]);++ // Adds a keyboard shortcut to toggle the sidebar.+ React.useEffect(() => {+ const handleKeyDown = (event: KeyboardEvent) => {+ if (+ isMobile &&+ event.key === SIDEBAR_KEYBOARD_SHORTCUT &&+ (event.metaKey || event.ctrlKey)+ ) {+ event.preventDefault();+ toggleSidebar();+ }+ };++ window.addEventListener("keydown", handleKeyDown);+ return () => window.removeEventListener("keydown", handleKeyDown);+ }, [isMobile, toggleSidebar]);++ // We add a state so that we can do data-state="expanded" or "collapsed".+ // This makes it easier to style the sidebar with Tailwind classes.+ const state = open ? "expanded" : "collapsed";++ const contextValue = React.useMemo<SidebarContextProps>(+ () => ({+ state,+ open,+ setOpen,+ isMobile,+ openMobile,+ setOpenMobile,+ toggleSidebar,+ }),+ [state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar],+ );++ return (+ <SidebarContext.Provider value={contextValue}>+ <div+ data-slot="sidebar-wrapper"+ style={+ {+ "--sidebar-width": SIDEBAR_WIDTH,+ "--sidebar-width-icon": SIDEBAR_WIDTH_ICON,+ ...style,+ } as React.CSSProperties+ }+ className={cn(+ "group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar",+ className,+ )}+ {...props}+ >+ {children}+ </div>+ </SidebarContext.Provider>+ );+}++function Sidebar({+ side = "left",+ variant = "sidebar",+ collapsible = "offcanvas",+ className,+ children,+ dir,+ ...props+}: React.ComponentProps<"div"> & {+ side?: "left" | "right";+ variant?: "sidebar" | "floating" | "inset";+ collapsible?: "offcanvas" | "icon" | "none";+}) {+ const { isMobile, state, openMobile, setOpenMobile } = useSidebar();++ if (collapsible === "none") {+ return (+ <div+ data-slot="sidebar"+ className={cn(+ "flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground",+ className,+ )}+ {...props}+ >+ {children}+ </div>+ );+ }++ if (isMobile) {+ return (+ <Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>+ <SheetContent+ dir={dir}+ data-sidebar="sidebar"+ data-slot="sidebar"+ data-mobile="true"+ className="w-(--sidebar-width) bg-sidebar p-0 text-sidebar-foreground"+ style={+ {+ "--sidebar-width": SIDEBAR_WIDTH_MOBILE,+ width: SIDEBAR_WIDTH_MOBILE,+ } as React.CSSProperties+ }+ side={side}+ >+ <SheetHeader className="sr-only">+ <SheetTitle>Sidebar</SheetTitle>+ <SheetDescription>Displays the mobile sidebar.</SheetDescription>+ </SheetHeader>+ <div className="flex h-full w-full flex-col">{children}</div>+ </SheetContent>+ </Sheet>+ );+ }++ return (+ <div+ className="group peer hidden text-sidebar-foreground md:block"+ data-state={state}+ data-collapsible={state === "collapsed" ? collapsible : ""}+ data-variant={variant}+ data-side={side}+ data-slot="sidebar"+ >+ {/* This is what handles the sidebar gap on desktop */}+ <div+ data-slot="sidebar-gap"+ className={cn(+ "relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",+ "group-data-[collapsible=offcanvas]:w-0",+ "group-data-[side=right]:rotate-180",+ variant === "floating" || variant === "inset"+ ? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"+ : "group-data-[collapsible=icon]:w-(--sidebar-width-icon)",+ )}+ />+ <div+ data-slot="sidebar-container"+ data-side={side}+ className={cn(+ "fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear data-[side=left]:left-0 data-[side=left]:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)] data-[side=right]:right-0 data-[side=right]:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)] md:flex",+ // Adjust the padding for floating and inset variants.+ variant === "floating" || variant === "inset"+ ? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"+ : "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",+ className,+ )}+ {...props}+ >+ <div+ data-sidebar="sidebar"+ data-slot="sidebar-inner"+ className="flex size-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:shadow-sm group-data-[variant=floating]:ring-1 group-data-[variant=floating]:ring-sidebar-border"+ >+ {children}+ </div>+ </div>+ </div>+ );+}++function SidebarTrigger({+ className,+ onClick,+ ...props+}: React.ComponentProps<typeof Button>) {+ const { toggleSidebar } = useSidebar();++ return (+ <Button+ data-sidebar="trigger"+ data-slot="sidebar-trigger"+ variant="ghost"+ size="icon-sm"+ className={cn(className)}+ onClick={(event) => {+ onClick?.(event);+ toggleSidebar();+ }}+ {...props}+ >+ <PanelLeftIcon />+ <span className="sr-only">Toggle Sidebar</span>+ </Button>+ );+}++function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {+ const { toggleSidebar } = useSidebar();++ return (+ <button+ data-sidebar="rail"+ data-slot="sidebar-rail"+ aria-label="Toggle Sidebar"+ tabIndex={-1}+ onClick={toggleSidebar}+ title="Toggle Sidebar"+ className={cn(+ "absolute inset-y-0 z-20 hidden w-4 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:start-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex ltr:-translate-x-1/2 rtl:-translate-x-1/2",+ "in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",+ "[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",+ "group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar",+ "[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",+ "[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",+ className,+ )}+ {...props}+ />+ );+}++function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {+ return (+ <main+ data-slot="sidebar-inset"+ className={cn(+ "relative flex w-full flex-1 flex-col bg-background md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",+ className,+ )}+ {...props}+ />+ );+}++function SidebarInput({+ className,+ ...props+}: React.ComponentProps<typeof Input>) {+ return (+ <Input+ data-slot="sidebar-input"+ data-sidebar="input"+ className={cn("h-8 w-full bg-background shadow-none", className)}+ {...props}+ />+ );+}++function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="sidebar-header"+ data-sidebar="header"+ className={cn("flex flex-col gap-2 p-2", className)}+ {...props}+ />+ );+}++function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="sidebar-footer"+ data-sidebar="footer"+ className={cn("flex flex-col gap-2 p-2", className)}+ {...props}+ />+ );+}++function SidebarSeparator({+ className,+ ...props+}: React.ComponentProps<typeof Separator>) {+ return (+ <Separator+ data-slot="sidebar-separator"+ data-sidebar="separator"+ className={cn("mx-2 w-auto bg-sidebar-border", className)}+ {...props}+ />+ );+}++function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="sidebar-content"+ data-sidebar="content"+ className={cn(+ "no-scrollbar flex min-h-0 flex-1 flex-col gap-0 overflow-auto group-data-[collapsible=icon]:overflow-hidden",+ className,+ )}+ {...props}+ />+ );+}++function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="sidebar-group"+ data-sidebar="group"+ className={cn("relative flex w-full min-w-0 flex-col p-2", className)}+ {...props}+ />+ );+}++function SidebarGroupLabel({+ className,+ render,+ ...props+}: useRender.ComponentProps<"div"> & React.ComponentProps<"div">) {+ return useRender({+ defaultTagName: "div",+ props: mergeProps<"div">(+ {+ className: cn(+ "flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 ring-sidebar-ring outline-hidden transition-[margin,opacity] duration-200 ease-linear group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0 focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",+ className,+ ),+ },+ props,+ ),+ render,+ state: {+ slot: "sidebar-group-label",+ sidebar: "group-label",+ },+ });+}++function SidebarGroupAction({+ className,+ render,+ ...props+}: useRender.ComponentProps<"button"> & React.ComponentProps<"button">) {+ return useRender({+ defaultTagName: "button",+ props: mergeProps<"button">(+ {+ className: cn(+ "absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground ring-sidebar-ring outline-hidden transition-transform group-data-[collapsible=icon]:hidden after:absolute after:-inset-2 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 md:after:hidden [&>svg]:size-4 [&>svg]:shrink-0",+ className,+ ),+ },+ props,+ ),+ render,+ state: {+ slot: "sidebar-group-action",+ sidebar: "group-action",+ },+ });+}++function SidebarGroupContent({+ className,+ ...props+}: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="sidebar-group-content"+ data-sidebar="group-content"+ className={cn("w-full text-sm", className)}+ {...props}+ />+ );+}++function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {+ return (+ <ul+ data-slot="sidebar-menu"+ data-sidebar="menu"+ className={cn("flex w-full min-w-0 flex-col gap-0", className)}+ {...props}+ />+ );+}++function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {+ return (+ <li+ data-slot="sidebar-menu-item"+ data-sidebar="menu-item"+ className={cn("group/menu-item relative", className)}+ {...props}+ />+ );+}++const sidebarMenuButtonVariants = cva(+ "peer/menu-button group/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm ring-sidebar-ring outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-open:hover:bg-sidebar-accent data-open:hover:text-sidebar-accent-foreground data-active:bg-sidebar-accent data-active:font-medium data-active:text-sidebar-accent-foreground [&_svg]:size-4 [&_svg]:shrink-0 [&>span:last-child]:truncate",+ {+ variants: {+ variant: {+ default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",+ outline:+ "bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_var(--sidebar-accent)]",+ },+ size: {+ default: "h-8 text-sm",+ sm: "h-7 text-xs",+ lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",+ },+ },+ defaultVariants: {+ variant: "default",+ size: "default",+ },+ },+);++function SidebarMenuButton({+ render,+ isActive = false,+ variant = "default",+ size = "default",+ tooltip,+ className,+ ...props+}: useRender.ComponentProps<"button"> &+ React.ComponentProps<"button"> & {+ isActive?: boolean;+ tooltip?: string | React.ComponentProps<typeof TooltipContent>;+ } & VariantProps<typeof sidebarMenuButtonVariants>) {+ const { isMobile, state } = useSidebar();+ const comp = useRender({+ defaultTagName: "button",+ props: mergeProps<"button">(+ {+ className: cn(sidebarMenuButtonVariants({ variant, size }), className),+ },+ props,+ ),+ render: !tooltip ? render : <TooltipTrigger render={render} />,+ state: {+ slot: "sidebar-menu-button",+ sidebar: "menu-button",+ size,+ active: isActive,+ },+ });++ if (!tooltip) {+ return comp;+ }++ if (typeof tooltip === "string") {+ tooltip = {+ children: tooltip,+ };+ }++ return (+ <Tooltip>+ {comp}+ <TooltipContent+ side="right"+ align="center"+ hidden={state !== "collapsed" || isMobile}+ {...tooltip}+ />+ </Tooltip>+ );+}++function SidebarMenuAction({+ className,+ render,+ showOnHover = false,+ ...props+}: useRender.ComponentProps<"button"> &+ React.ComponentProps<"button"> & {+ showOnHover?: boolean;+ }) {+ return useRender({+ defaultTagName: "button",+ props: mergeProps<"button">(+ {+ className: cn(+ "absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground ring-sidebar-ring outline-hidden transition-transform group-data-[collapsible=icon]:hidden peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[size=default]/menu-button:top-1.5 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1 after:absolute after:-inset-2 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 md:after:hidden [&>svg]:size-4 [&>svg]:shrink-0",+ showOnHover &&+ "group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 peer-data-active/menu-button:text-sidebar-accent-foreground aria-expanded:opacity-100 md:opacity-0",+ className,+ ),+ },+ props,+ ),+ render,+ state: {+ slot: "sidebar-menu-action",+ sidebar: "menu-action",+ },+ });+}++function SidebarMenuBadge({+ className,+ ...props+}: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="sidebar-menu-badge"+ data-sidebar="menu-badge"+ className={cn(+ "pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium text-sidebar-foreground tabular-nums select-none group-data-[collapsible=icon]:hidden peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[size=default]/menu-button:top-1.5 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1 peer-data-active/menu-button:text-sidebar-accent-foreground",+ className,+ )}+ {...props}+ />+ );+}++function SidebarMenuSkeleton({+ className,+ showIcon = false,+ ...props+}: React.ComponentProps<"div"> & {+ showIcon?: boolean;+}) {+ // Random width between 50 to 90%.+ const [width] = React.useState(() => {+ return `${Math.floor(Math.random() * 40) + 50}%`;+ });++ return (+ <div+ data-slot="sidebar-menu-skeleton"+ data-sidebar="menu-skeleton"+ className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}+ {...props}+ >+ {showIcon && (+ <Skeleton+ className="size-4 rounded-md"+ data-sidebar="menu-skeleton-icon"+ />+ )}+ <Skeleton+ className="h-4 max-w-(--skeleton-width) flex-1"+ data-sidebar="menu-skeleton-text"+ style={+ {+ "--skeleton-width": width,+ } as React.CSSProperties+ }+ />+ </div>+ );+}++function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {+ return (+ <ul+ data-slot="sidebar-menu-sub"+ data-sidebar="menu-sub"+ className={cn(+ "mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5 group-data-[collapsible=icon]:hidden",+ className,+ )}+ {...props}+ />+ );+}++function SidebarMenuSubItem({+ className,+ ...props+}: React.ComponentProps<"li">) {+ return (+ <li+ data-slot="sidebar-menu-sub-item"+ data-sidebar="menu-sub-item"+ className={cn("group/menu-sub-item relative", className)}+ {...props}+ />+ );+}++function SidebarMenuSubButton({+ render,+ size = "md",+ isActive = false,+ className,+ ...props+}: useRender.ComponentProps<"a"> &+ React.ComponentProps<"a"> & {+ size?: "sm" | "md";+ isActive?: boolean;+ }) {+ return useRender({+ defaultTagName: "a",+ props: mergeProps<"a">(+ {+ className: cn(+ "flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground ring-sidebar-ring outline-hidden group-data-[collapsible=icon]:hidden hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[size=md]:text-sm data-[size=sm]:text-xs data-active:bg-sidebar-accent data-active:text-sidebar-accent-foreground [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground",+ className,+ ),+ },+ props,+ ),+ render,+ state: {+ slot: "sidebar-menu-sub-button",+ sidebar: "menu-sub-button",+ size,+ active: isActive,+ },+ });+}++export {+ Sidebar,+ SidebarContent,+ SidebarFooter,+ SidebarGroup,+ SidebarGroupAction,+ SidebarGroupContent,+ SidebarGroupLabel,+ SidebarHeader,+ SidebarInput,+ SidebarInset,+ SidebarMenu,+ SidebarMenuAction,+ SidebarMenuBadge,+ SidebarMenuButton,+ SidebarMenuItem,+ SidebarMenuSkeleton,+ SidebarMenuSub,+ SidebarMenuSubButton,+ SidebarMenuSubItem,+ SidebarProvider,+ SidebarRail,+ SidebarSeparator,+ SidebarTrigger,+ useSidebar,+};diff --git a/src/client/features/projects/ProjectSwitcher.tsx b/src/client/features/projects/ProjectSwitcher.tsxindex 68dfaa3f..8e1a86a1 100644--- a/src/client/features/projects/ProjectSwitcher.tsx+++ b/src/client/features/projects/ProjectSwitcher.tsx@@ -3,93 +3,54 @@ import { projectsQueryOptions } from "@/client/features/projects/projectQueries"import { Link, useRouter } from "@tanstack/react-router";import { useQuery } from "@tanstack/react-query";import { findLast } from "remeda";-import {- Check,- ChevronsUpDown,- FolderCog,- Plus,- Search,- Settings,-} from "lucide-react";+import { FolderCog, Plus, Settings } from "lucide-react";import { setLastProjectId } from "@/client/lib/active-project";import { CreateProjectModal } from "@/client/features/projects/CreateProjectModal";+import {+ Combobox,+ ComboboxContent,+ ComboboxEmpty,+ ComboboxInput,+ ComboboxItem,+ ComboboxList,+ ComboboxTrigger,+} from "@/client/components/ui/combobox";+import { Button } from "@/client/components/ui/button";+import { Separator } from "@/client/components/ui/separator";import type { ProjectSummary } from "./types";-// Below this many projects the plain list is faster to scan than a search box.const SEARCH_THRESHOLD = 8;+function matchesProject(project: ProjectSummary, query: string) {+ const needle = query.trim().toLowerCase();+ return (+ project.name.toLowerCase().includes(needle) ||+ Boolean(project.domain?.toLowerCase().includes(needle))+ );+}+export function ProjectSwitcher({activeProjectId,onCloseDrawer,}: {activeProjectId: string | null;- // Mobile sidebar passes this so switching / navigating away also closes the- // drawer overlay.onCloseDrawer?: () => void;}) {- // Matches are read off router.state at click time; subscribing via- // useMatches() would re-render the whole sidebar on every route change for- // a value only a click needs.const router = useRouter();const [creating, setCreating] = React.useState(false);- // Controlled open state rather than daisyUI's CSS focus-within dropdown:- // focus-within can't guarantee the search input ends up focused on open- // (Safari never focuses buttons on click, and moving focus into the panel- // is exactly what a combobox needs).const [open, setOpen] = React.useState(false);- const [query, setQuery] = React.useState("");- const [highlightIndex, setHighlightIndex] = React.useState(0);- const rootRef = React.useRef<HTMLDivElement>(null);- const triggerRef = React.useRef<HTMLButtonElement>(null);- const searchInputRef = React.useRef<HTMLInputElement>(null);- const listRef = React.useRef<HTMLUListElement>(null);-const projectsQuery = useQuery(projectsQueryOptions());const projects = projectsQuery.data ?? [];const activeProject =projects.find((project) => project.id === activeProjectId) ?? null;- const showSearch = projects.length >= SEARCH_THRESHOLD;- const normalizedQuery = query.trim().toLowerCase();- const filteredProjects = normalizedQuery- ? projects.filter(- (project) =>- project.name.toLowerCase().includes(normalizedQuery) ||- project.domain?.toLowerCase().includes(normalizedQuery),- )- : projects;-- const openPanel = () => {- setQuery("");- setHighlightIndex(0);- setOpen(true);- };-- const closePanel = () => {- setOpen(false);- setQuery("");- };-- // Opening the panel puts the caret straight in the search box, so- // click → type → Enter selects a project with no extra step. Touch devices- // are skipped: autofocus would pop the keyboard over the list.- React.useEffect(() => {- if (!open || !showSearch) return;- if (window.matchMedia("(pointer: coarse)").matches) return;- searchInputRef.current?.focus();- }, [open, showSearch]);-const handleSelect = (project: ProjectSummary) => {- closePanel();+ setOpen(false);onCloseDrawer?.();if (project.id === activeProjectId) return;setLastProjectId(project.id);- // Stay on the current page in the new project: the deepest matched route- // whose path's only dynamic segment is the project id. Deeper routes (a- // rank tracker, an audit result) reference entities owned by the old- // project, so they fall back to their section. Filtering on the path- // template rather than match.params matters: the router gives every match- // the location's full param set, so params can't tell layers apart.+ // Keep the current section when it exists in the new project. Detail+ // routes refer to entities in the old project and fall back to the section.const stayable = findLast(router.state.matches,(match) =>@@ -100,283 +61,124 @@ export function ProjectSwitcher({(segment) => !segment.startsWith("$") || segment === "$projectId",),);- // Navigating by href keeps typed-route generics out of a dynamic target- // while still running search validation; search params are deliberately- // not carried over — filters and session ids belong to the old project.const template = stayable?.fullPath ?? "/p/$projectId";void router.navigate({href: template.split("$projectId").join(project.id).replace(/\/$/, ""),});};- const moveHighlight = (delta: number) => {- setHighlightIndex((index) => {- const next = index + delta;- if (next < 0) return 0;- if (next > filteredProjects.length - 1)- return filteredProjects.length - 1;- return next;- });- };-- const handleSearchKeyDown = (event: React.KeyboardEvent) => {- if (event.key === "ArrowDown") {- event.preventDefault();- moveHighlight(1);- } else if (event.key === "ArrowUp") {- event.preventDefault();- moveHighlight(-1);- } else if (event.key === "Enter") {- event.preventDefault();- const project = filteredProjects[highlightIndex] ?? filteredProjects[0];- if (project) handleSelect(project);- }- // Escape is handled once at the root so it also works from the project- // list and footer buttons.- };-- // Type-ahead fallback on the trigger: if the user types while focus is- // still on the trigger (touch skips autofocus; focus can also stay here- // between open and the focus effect), open the panel and route the- // keystroke into the search box instead of dropping it. Deliberately not- // on the wrapper — that would also swallow keystrokes bubbling from the- // menu items and the create-project modal rendered inside it.- const handleTriggerKeyDown = (event: React.KeyboardEvent) => {- if (!showSearch) return;- const isCharacter =- event.key.length === 1 &&- !event.metaKey &&- !event.ctrlKey &&- !event.altKey;- if (isCharacter || event.key === "Backspace") {- event.preventDefault();- if (!open) setOpen(true);- setQuery((current) =>- isCharacter ? current + event.key : current.slice(0, -1),- );- setHighlightIndex(0);- searchInputRef.current?.focus();- } else if (!open && event.key === "ArrowDown") {- event.preventDefault();- openPanel();- } else if (open && ["ArrowDown", "ArrowUp", "Enter"].includes(event.key)) {- handleSearchKeyDown(event);- }- };-- // Escape closes the panel from anywhere inside the switcher — trigger,- // search box, project list, or footer. When the create-project modal is up- // the panel is already closed, so this never swallows the modal's own- // Escape handling.- const handleRootKeyDown = (event: React.KeyboardEvent) => {- if (event.key !== "Escape" || !open) return;- event.preventDefault();- closePanel();- triggerRef.current?.focus();- };-- // Close on clicks outside the switcher. Focus loss alone isn't used for- // this (clicking a non-focusable spot inside the panel blurs to <body>),- // so pointerdown containment is the single source of truth for "outside".- React.useEffect(() => {- if (!open) return;- const handlePointerDown = (event: PointerEvent) => {- const target = event.target;- if (!(target instanceof Node) || !rootRef.current?.contains(target)) {- closePanel();- }- };- document.addEventListener("pointerdown", handlePointerDown);- return () => document.removeEventListener("pointerdown", handlePointerDown);- }, [open]);-- // Also close when keyboard focus tabs out of the switcher entirely.- const handleRootBlur = (event: React.FocusEvent) => {- if (!open) return;- const next = event.relatedTarget;- if (next instanceof Node && !rootRef.current?.contains(next)) closePanel();- };-- // Keep the keyboard highlight visible while arrowing through a scrolled- // list.- React.useEffect(() => {- const highlighted = listRef.current?.querySelector(- '[data-highlighted="true"]',- );- highlighted?.scrollIntoView({ block: "nearest" });- }, [highlightIndex]);-return (- <div- ref={rootRef}- onBlur={handleRootBlur}- onKeyDown={handleRootKeyDown}- // Hand-rolled positioning instead of daisyUI's .dropdown: its CSS also- // shows the panel on :focus-within, which fights the controlled `open`- // state (e.g. the panel would stay visible after closing while the- // trigger still has focus).- className="relative w-full"- >- <div className="flex items-stretch rounded-lg border border-base-300 bg-base-100">- <button- ref={triggerRef}- type="button"- aria-label="Switch project"- aria-expanded={open}- aria-haspopup="listbox"- onClick={() => (open ? closePanel() : openPanel())}- onKeyDown={handleTriggerKeyDown}- className="flex min-w-0 flex-1 items-center justify-between gap-2 rounded-l-lg px-3 py-1.5 text-left transition-colors hover:bg-base-200"- >- <span className="flex min-w-0 flex-col">- <span className="truncate text-sm font-medium text-base-content">- {activeProject?.name ?? "Select project"}- </span>- {activeProject?.domain ? (- <span className="truncate text-xs font-normal text-base-content/50">- {activeProject.domain}- </span>- ) : null}- </span>- <ChevronsUpDown className="size-3.5 shrink-0 text-base-content/40" />- </button>- {activeProject ? (- <Link- to="/p/$projectId/settings"- params={{ projectId: activeProject.id }}- aria-label="Project settings"- title="Project settings"- onClick={() => {- closePanel();- onCloseDrawer?.();- }}- className="flex shrink-0 items-center justify-center rounded-r-lg border-l border-base-300 px-2.5 text-base-content/60 transition-colors hover:bg-base-200 hover:text-base-content"+ <>+ <Combobox+ items={projects}+ value={activeProject}+ itemToStringLabel={(project) => project.name}+ isItemEqualToValue={(project, value) => project.id === value.id}+ filter={matchesProject}+ autoHighlight+ open={open}+ onOpenChange={setOpen}+ onValueChange={(project) => {+ if (project) handleSelect(project);+ }}+ >+ <div className="flex items-stretch rounded-lg border border-sidebar-border bg-card">+ <ComboboxTrigger+ aria-label="Switch project"+ className="flex min-w-0 flex-1 items-center justify-between gap-2 rounded-l-lg px-3 py-1.5 text-left hover:bg-accent">- <Settings className="size-4" />- </Link>- ) : null}- </div>-- {open ? (- <div className="absolute left-0 right-0 top-full z-30 mt-1 overflow-hidden rounded-box border border-base-300 bg-base-100 shadow-lg">- {showSearch ? (- <div className="border-b border-base-300 p-2">- <label className="input input-sm w-full">- <Search className="size-3.5 shrink-0 text-base-content/40" />- <input- ref={searchInputRef}- type="text"- value={query}- placeholder="Find project…"- aria-label="Filter projects"- aria-controls="project-switcher-listbox"- aria-activedescendant={- filteredProjects[highlightIndex]- ? `project-option-${filteredProjects[highlightIndex].id}`- : undefined- }- className="grow"- onChange={(event) => {- setQuery(event.target.value);- setHighlightIndex(0);+ <span className="flex min-w-0 flex-col">+ <span className="truncate text-sm font-medium">+ {activeProject?.name ?? "Select project"}+ </span>+ {activeProject?.domain ? (+ <span className="truncate text-xs text-muted-foreground">+ {activeProject.domain}+ </span>+ ) : null}+ </span>+ </ComboboxTrigger>+ {activeProject ? (+ <Button+ nativeButton={false}+ render={+ <Link+ to="/p/$projectId/settings"+ params={{ projectId: activeProject.id }}+ aria-label="Project settings"+ title="Project settings"+ onClick={() => {+ setOpen(false);+ onCloseDrawer?.();}}- onKeyDown={handleSearchKeyDown}/>- </label>- </div>- ) : null}-- {projects.length > 0 ? (- // Long project lists scroll inside the dropdown; without the cap the- // menu grows past the viewport and the footer becomes unreachable.- // flex-nowrap because daisyUI menus wrap into columns by default.- <ul- ref={listRef}- id="project-switcher-listbox"- role="listbox"- aria-label="Projects"- className="menu max-h-[min(60vh,21rem)] w-full flex-nowrap overflow-y-auto p-2"+ }+ variant="ghost"+ className="h-auto self-stretch rounded-l-none border-0 border-l border-sidebar-border">- {filteredProjects.map((project, index) => {- const isActive = project.id === activeProjectId;- const isHighlighted = showSearch && index === highlightIndex;- return (- <li key={project.id} role="presentation">- <button- type="button"- id={`project-option-${project.id}`}- role="option"- aria-selected={isActive}- data-highlighted={isHighlighted || undefined}- onClick={() => handleSelect(project)}- onMouseEnter={- showSearch ? () => setHighlightIndex(index) : undefined- }- className={- isActive ? "active" : isHighlighted ? "bg-base-200" : ""- }- >- <span className="flex min-w-0 flex-1 flex-col">- <span className="truncate">{project.name}</span>- {project.domain ? (- <span className="truncate text-xs text-base-content/50">- {project.domain}- </span>- ) : null}- </span>- {isActive ? (- <Check className="size-4 shrink-0 text-primary" />- ) : null}- </button>- </li>- );- })}- {filteredProjects.length === 0 ? (- <li className="menu-disabled">- <span className="text-base-content/50">- No projects match “{query.trim()}”- </span>- </li>- ) : null}- </ul>+ <Settings className="size-4" />+ </Button>) : null}-- <ul- className={`menu w-full shrink-0 p-2 ${- projects.length > 0 ? "border-t border-base-300" : ""- }`}- >- <li>- <button- type="button"- onClick={() => {- closePanel();- // Deliberately leave the mobile drawer open: the modal is- // rendered inside it, so closing the drawer would unmount the- // modal. The drawer closes when the modal does.- setCreating(true);- }}- >- <Plus className="size-4" />- New project- </button>- </li>- <li>- <Link- to="/projects"- onClick={() => {- closePanel();- onCloseDrawer?.();- }}- >- <FolderCog className="size-4" />- Manage projects- </Link>- </li>- </ul></div>- ) : null}-+ <ComboboxContent className="w-(--anchor-width)">+ {projects.length >= SEARCH_THRESHOLD ? (+ <ComboboxInput+ className="w-auto"+ placeholder="Find project…"+ aria-label="Filter projects"+ showTrigger={false}+ />+ ) : null}+ {projects.length > 0 ? (+ <ComboboxEmpty>No projects match.</ComboboxEmpty>+ ) : null}+ <ComboboxList className="max-h-[min(60vh,21rem)]">+ {(project: ProjectSummary) => (+ <ComboboxItem key={project.id} value={project}>+ <span className="flex min-w-0 flex-col">+ <span className="truncate">{project.name}</span>+ {project.domain ? (+ <span className="truncate text-xs text-muted-foreground">+ {project.domain}+ </span>+ ) : null}+ </span>+ </ComboboxItem>+ )}+ </ComboboxList>+ <Separator />+ <div className="grid gap-0.5 p-1">+ <Button+ variant="ghost"+ className="justify-start"+ onClick={() => {+ setOpen(false);+ setCreating(true);+ }}+ >+ <Plus className="size-4" />+ New project+ </Button>+ <Button+ nativeButton={false}+ render={+ <Link+ to="/projects"+ onClick={() => {+ setOpen(false);+ onCloseDrawer?.();+ }}+ />+ }+ variant="ghost"+ className="justify-start"+ >+ <FolderCog className="size-4" />+ Manage projects+ </Button>+ </div>+ </ComboboxContent>+ </Combobox>{creating ? (<CreateProjectModalonClose={() => {@@ -385,6 +187,6 @@ export function ProjectSwitcher({}}/>) : null}- </div>+ </>);}diff --git a/src/client/hooks/use-mobile.ts b/src/client/hooks/use-mobile.tsnew file mode 100644index 00000000..a93d5839--- /dev/null+++ b/src/client/hooks/use-mobile.ts@@ -0,0 +1,21 @@+import * as React from "react";++const MOBILE_BREAKPOINT = 768;++export function useIsMobile() {+ const [isMobile, setIsMobile] = React.useState<boolean | undefined>(+ undefined,+ );++ React.useEffect(() => {+ const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);+ const onChange = () => {+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);+ };+ mql.addEventListener("change", onChange);+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);+ return () => mql.removeEventListener("change", onChange);+ }, []);++ return !!isMobile;+}diff --git a/src/client/layout/AppShell.tsx b/src/client/layout/AppShell.tsxindex e40a6008..580470da 100644--- a/src/client/layout/AppShell.tsx+++ b/src/client/layout/AppShell.tsx@@ -2,10 +2,8 @@ import * as React from "react";import { projectsQueryOptions } from "@/client/features/projects/projectQueries";import { Link, useLocation } from "@tanstack/react-router";import { useQuery } from "@tanstack/react-query";-import { Menu } from "lucide-react";import {MissingSeoSetupModal,- MobileSidebarDrawer,SeoApiStatusBanners,} from "@/client/layout/AppShellParts";import { GscReEngagementModal } from "@/client/features/gsc/GscReEngagementModal";@@ -14,6 +12,11 @@ import { BILLING_ROUTE } from "@/shared/billing";import { getSeoApiKeyStatus } from "@/serverFunctions/config";import { getLastProjectId } from "@/client/lib/active-project";import { dataforseoHelpLinkOptions } from "@/client/navigation/items";+import {+ SidebarInset,+ SidebarProvider,+ SidebarTrigger,+} from "@/client/components/ui/sidebar";export function AuthenticatedAppLayout({children,@@ -25,7 +28,6 @@ export function AuthenticatedAppLayout({banner?: React.ReactNode;}) {const location = useLocation();- const [drawerOpen, setDrawerOpen] = React.useState(false);const [showMissingSeoApiKeyModal, setShowMissingSeoApiKeyModal] =React.useState(false);// On non-project pages (e.g. /settings) there's no projectId in the URL, so@@ -96,39 +98,17 @@ export function AuthenticatedAppLayout({!showMissingSeoApiKeyModal;return (- <div className="flex h-[100dvh] bg-sidebar">- <div className="hidden shrink-0 md:block">- <Sidebar projectId={sidebarProjectId} />- </div>-- <div className="flex min-w-0 flex-1 flex-col">- <MobileTopBar- drawerOpen={drawerOpen}- onOpenDrawer={() => setDrawerOpen(true)}+ <SidebarProvider className="h-[100dvh] min-h-0 overflow-hidden">+ <Sidebar projectId={sidebarProjectId} />+ <SidebarInset className="min-h-0 overflow-hidden md:!m-0 md:!mt-2 md:!rounded-none md:!rounded-tl-lg md:border-l md:border-t md:border-sidebar-border md:!shadow-none">+ <MobileTopBar />+ <SeoApiStatusBanners+ shouldShowSeoApiWarning={shouldShowSeoApiWarning}+ seoApiKeyStatusError={seoApiKeyStatusError}/>-- {/* PostHog-style cutout: the main content sits on an inset panel with a- thin strip of the sidebar background above it and a hairline border.- Cards inside the panel use bg-base-100 to stand out from it. */}- <div className="flex min-h-0 flex-1 flex-col md:pt-2">- <div className="flex min-h-0 flex-1 flex-col overflow-hidden bg-background md:rounded-tl-lg md:border-l md:border-t md:border-sidebar-border">- <SeoApiStatusBanners- shouldShowSeoApiWarning={shouldShowSeoApiWarning}- seoApiKeyStatusError={seoApiKeyStatusError}- />-- {banner}-- <div className="min-h-0 flex-1 overflow-auto">{children}</div>- </div>- </div>- </div>-- <MobileSidebarDrawer- open={drawerOpen}- projectId={sidebarProjectId}- onClose={() => setDrawerOpen(false)}- />+ {banner}+ <div className="min-h-0 flex-1 overflow-auto">{children}</div>+ </SidebarInset>{showMissingSeoApiKeyModal ? (<MissingSeoSetupModal@@ -140,29 +120,15 @@ export function AuthenticatedAppLayout({projectId={sidebarProjectId}suppressed={showMissingSeoApiKeyModal}/>- </div>+ </SidebarProvider>);}-function MobileTopBar({- drawerOpen,- onOpenDrawer,-}: {- drawerOpen: boolean;- onOpenDrawer: () => void;-}) {+function MobileTopBar() {return (- <div className="flex shrink-0 items-center gap-1 border-b border-base-300 bg-base-100 px-2 py-1.5 md:hidden">- <button- type="button"- className="btn btn-square btn-ghost btn-sm"- aria-label="Toggle sidebar"- aria-expanded={drawerOpen}- onClick={onOpenDrawer}- >- <Menu className="h-5 w-5" />- </button>- <Link to="/" className="ml-1 font-semibold text-base-content">+ <div className="flex shrink-0 items-center gap-1 border-b border-border bg-card px-2 py-1.5 md:hidden">+ <SidebarTrigger aria-label="Toggle sidebar" />+ <Link to="/" className="ml-1 font-semibold text-foreground">OpenSEO</Link></div>diff --git a/src/client/layout/AppShellParts.tsx b/src/client/layout/AppShellParts.tsxindex 591c4987..7bea9a7b 100644--- a/src/client/layout/AppShellParts.tsx+++ b/src/client/layout/AppShellParts.tsx@@ -1,9 +1,16 @@import { Link } from "@tanstack/react-router";import { AlertTriangle, ExternalLink } from "lucide-react";-import { Modal } from "@/client/components/Modal";-import { Sidebar } from "@/client/components/Sidebar";import { AppBanner } from "@/client/layout/AppBanner";import { dataforseoHelpLinkOptions } from "@/client/navigation/items";+import { Button } from "@/client/components/ui/button";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from "@/client/components/ui/dialog";function SeoApiStatusBanners({shouldShowSeoApiWarning,@@ -16,7 +23,7 @@ function SeoApiStatusBanners({const helpLink = (<Link{...dataforseoHelpLinkOptions}- className="link link-primary font-medium"+ className="font-medium text-primary underline-offset-4 hover:underline">help page</Link>@@ -40,71 +47,36 @@ function SeoApiStatusBanners({);}-function MobileSidebarDrawer({- open,- projectId,- onClose,-}: {- open: boolean;- projectId: string | null;- onClose: () => void;-}) {- if (!open) return null;-- return (- <div className="fixed inset-0 z-50 md:hidden">- <button- type="button"- aria-label="Close sidebar"- className="absolute inset-0 bg-black/45"- onClick={onClose}- />- <div className="absolute left-0 top-0 h-full shadow-xl">- <Sidebar projectId={projectId} onNavigate={onClose} onClose={onClose} />- </div>- </div>- );-}-function MissingSeoSetupModal({ onClose }: { onClose: () => void }) {return (- <Modal- maxWidth="max-w-lg"- onClose={onClose}- labelledBy="dataforseo-setup-title"- >- <div className="flex items-start gap-3">- <div className="rounded-full bg-warning/20 p-2 text-warning">- <AlertTriangle className="size-5" />- </div>- <div className="space-y-2">- <h2- id="dataforseo-setup-title"- className="text-lg font-semibold text-base-content"+ <Dialog open onOpenChange={(open) => !open && onClose()}>+ <DialogContent className="max-w-lg">+ <DialogHeader className="flex-row items-start gap-3 text-left">+ <div className="rounded-full bg-warning/20 p-2 text-warning">+ <AlertTriangle className="size-5" />+ </div>+ <div className="space-y-2">+ <DialogTitle>One quick setup step</DialogTitle>+ <DialogDescription>+ Add your DataForSEO API key to start using OpenSEO.+ </DialogDescription>+ </div>+ </DialogHeader>+ <DialogFooter>+ <Button variant="ghost" onClick={onClose}>+ Dismiss+ </Button>+ <Button+ nativeButton={false}+ render={<Link {...dataforseoHelpLinkOptions} onClick={onClose} />}>- One quick setup step- </h2>- <p className="text-sm text-base-content/75">- Add your DataForSEO API key to start using OpenSEO.- </p>- </div>- </div>-- <div className="mt-1 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">- <button type="button" className="btn btn-ghost" onClick={onClose}>- Dismiss- </button>- <Link- {...dataforseoHelpLinkOptions}- className="btn btn-primary"- onClick={onClose}- >- Open setup guide- <ExternalLink className="size-4" />- </Link>- </div>- </Modal>+ Open setup guide+ <ExternalLink className="size-4" />+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>);}-export { MissingSeoSetupModal, MobileSidebarDrawer, SeoApiStatusBanners };+export { MissingSeoSetupModal, SeoApiStatusBanners };diff --git a/src/client/lib/dropdown.ts b/src/client/lib/dropdown.tsdeleted file mode 100644index 0265f2e7..00000000--- a/src/client/lib/dropdown.ts+++ /dev/null@@ -1,7 +0,0 @@-// daisyUI dropdowns stay open until focus leaves, so blur the trigger to-// close the menu before navigating or acting on a selection.-export function closeDropdown() {- if (document.activeElement instanceof HTMLElement) {- document.activeElement.blur();- }-}