Skip to content

Commit

Permalink
feat: sidebar state
Browse files Browse the repository at this point in the history
  • Loading branch information
TinsFox committed Nov 2, 2024
1 parent 72a7125 commit c259d57
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"i18next": "^23.15.1",
"i18next-browser-languagedetector": "^8.0.0",
"input-otp": "^1.2.4",
"jotai": "^2.10.0",
"jotai": "^2.10.1",
"lodash-es": "^4.17.21",
"lucide-react": "^0.429.0",
"ofetch": "^1.4.0",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
10 changes: 0 additions & 10 deletions src/atoms/resizable-panels.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/nav-sidebar/nav-main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useMemo } from "react"
import { useTranslation } from "react-i18next"
import { Link, useLocation } from "react-router-dom"

import { navOpenItemsAtom } from "@/atoms/nav"
import {
Collapsible,
CollapsibleContent,
Expand All @@ -21,7 +22,6 @@ import {
SidebarMenuSubItem,
} from "@/components/ui/sidebar"
import type { IMenu } from "@/models/menu"
import { navOpenItemsAtom } from "@/store/nav"

export function NavMain({
items,
Expand Down
2 changes: 0 additions & 2 deletions src/components/ui/dropdown-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use client"

import * as React from "react"
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
import {
Expand Down
8 changes: 3 additions & 5 deletions src/components/ui/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
TooltipTrigger,
} from "@/components/ui/tooltip"

const SIDEBAR_COOKIE_NAME = "sidebar:state"
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
import { SIDEBAR_COOKIE_NAME } from "@/constants"

const SIDEBAR_WIDTH = "16rem"
const SIDEBAR_WIDTH_MOBILE = "18rem"
const SIDEBAR_WIDTH_ICON = "3rem"
Expand Down Expand Up @@ -81,9 +81,7 @@ const SidebarProvider = React.forwardRef<
} 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}`
localStorage.setItem(SIDEBAR_COOKIE_NAME, openState.toString())
},
[setOpenProp, open]
)
Expand Down
2 changes: 1 addition & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./layout"
export const SIDEBAR_COOKIE_NAME = "sidebar:state"
2 changes: 0 additions & 2 deletions src/constants/layout.ts

This file was deleted.

5 changes: 4 additions & 1 deletion src/pages/(admin)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import {
SidebarProvider,
SidebarTrigger,
} from "@/components/ui/sidebar"
import { SIDEBAR_COOKIE_NAME } from "@/constants"

export function Component() {
const sidebarState = localStorage.getItem(SIDEBAR_COOKIE_NAME) === "true"

return (
<SidebarProvider>
<SidebarProvider defaultOpen={sidebarState}>
<AppSidebar />
<SidebarInset className="w-full overflow-hidden">
<div className="sticky top-0 z-10">
Expand Down

0 comments on commit c259d57

Please sign in to comment.