refactor: simplify sidebar state handling

- Replaced direct state checks with a derived variable `isCollapsed` for better readability and maintainability.
- Updated class names and conditions in the SidebarLogo component to use the new `isCollapsed` variable.
- Adjusted overflow behavior in Sidebar and SidebarContent components for improved layout management.
This commit is contained in:
Mauricio Siu
2026-03-16 15:29:25 -06:00
parent c317ec39cb
commit ce4e37c75b
2 changed files with 15 additions and 19 deletions
+13 -17
View File
@@ -545,6 +545,7 @@ function SidebarLogo() {
const { mutateAsync: setDefaultOrganization, isPending: isSettingDefault } = const { mutateAsync: setDefaultOrganization, isPending: isSettingDefault } =
api.organization.setDefault.useMutation(); api.organization.setDefault.useMutation();
const { isMobile } = useSidebar(); const { isMobile } = useSidebar();
const isCollapsed = state === "collapsed" && !isMobile;
const { data: activeOrganization } = api.organization.active.useQuery(); const { data: activeOrganization } = api.organization.active.useQuery();
const { data: invitations, refetch: refetchInvitations } = const { data: invitations, refetch: refetchInvitations } =
@@ -570,7 +571,7 @@ function SidebarLogo() {
<SidebarMenu <SidebarMenu
className={cn( className={cn(
"flex gap-2", "flex gap-2",
state === "collapsed" isCollapsed
? "flex-col" ? "flex-col"
: "flex-row justify-between items-center", : "flex-row justify-between items-center",
)} )}
@@ -580,17 +581,17 @@ function SidebarLogo() {
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>
<SidebarMenuButton <SidebarMenuButton
size={state === "collapsed" ? "sm" : "lg"} size={isCollapsed ? "sm" : "lg"}
className={cn( className={cn(
"data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground", "data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground",
state === "collapsed" && isCollapsed &&
"flex justify-center items-center p-2 h-10 w-10 mx-auto", "flex justify-center items-center p-2 h-10 w-10 mx-auto",
)} )}
> >
<div <div
className={cn( className={cn(
"flex items-center gap-2", "flex items-center gap-2",
state === "collapsed" && "justify-center", isCollapsed && "justify-center",
)} )}
> >
<div <div
@@ -602,7 +603,7 @@ function SidebarLogo() {
<Logo <Logo
className={cn( className={cn(
"transition-all", "transition-all",
state === "collapsed" ? "size-4" : "size-5", isCollapsed ? "size-4" : "size-5",
)} )}
logoUrl={activeOrganization?.logo || undefined} logoUrl={activeOrganization?.logo || undefined}
/> />
@@ -610,7 +611,7 @@ function SidebarLogo() {
<div <div
className={cn( className={cn(
"flex flex-col items-start", "flex flex-col items-start",
state === "collapsed" && "hidden", isCollapsed && "hidden",
)} )}
> >
<p className="text-sm font-medium leading-none"> <p className="text-sm font-medium leading-none">
@@ -619,7 +620,7 @@ function SidebarLogo() {
</div> </div>
</div> </div>
<ChevronsUpDown <ChevronsUpDown
className={cn("ml-auto", state === "collapsed" && "hidden")} className={cn("ml-auto", isCollapsed && "hidden")}
/> />
</SidebarMenuButton> </SidebarMenuButton>
</DropdownMenuTrigger> </DropdownMenuTrigger>
@@ -768,7 +769,7 @@ function SidebarLogo() {
</SidebarMenuItem> </SidebarMenuItem>
{/* Notification Bell */} {/* Notification Bell */}
<SidebarMenuItem className={cn(state === "collapsed" && "mt-2")}> <SidebarMenuItem className={cn(isCollapsed && "mt-2")}>
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>
<Button <Button
@@ -776,7 +777,7 @@ function SidebarLogo() {
size="icon" size="icon"
className={cn( className={cn(
"relative", "relative",
state === "collapsed" && "h-8 w-8 p-1.5 mx-auto", isCollapsed && "h-8 w-8 p-1.5 mx-auto",
)} )}
> >
<Bell className="size-4" /> <Bell className="size-4" />
@@ -1145,14 +1146,9 @@ export default function Page({ children }: Props) {
</div> </div>
)} )}
{dokployVersion && ( {dokployVersion && (
<> <div className="px-3 text-xs text-muted-foreground text-center group-data-[collapsible=icon]:hidden">
<div className="px-3 text-xs text-muted-foreground text-center group-data-[collapsible=icon]:hidden"> Version {dokployVersion}
Version {dokployVersion} </div>
</div>
<div className="hidden text-xs text-muted-foreground text-center group-data-[collapsible=icon]:block">
{dokployVersion}
</div>
</>
)} )}
</SidebarMenu> </SidebarMenu>
</SidebarFooter> </SidebarFooter>
+2 -2
View File
@@ -213,7 +213,7 @@ const Sidebar = React.forwardRef<
} }
side={side} side={side}
> >
<div className="flex h-full w-full flex-col">{children}</div> <div className="flex h-full w-full flex-col overflow-hidden">{children}</div>
</SheetContent> </SheetContent>
</Sheet> </Sheet>
); );
@@ -412,7 +412,7 @@ const SidebarContent = React.forwardRef<
ref={ref} ref={ref}
data-sidebar="content" data-sidebar="content"
className={cn( className={cn(
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden", "flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-y-auto",
className, className,
)} )}
{...props} {...props}