From ed335b13a5b5fef1bc53dbc69b72bd1dba654cea Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 18 Jan 2023 16:17:38 +0000 Subject: [PATCH] feat: foldable sidebar --- src/components/dashboard/DashboardLayout.tsx | 117 +++++++++--------- src/components/dashboard/DashboardMain.tsx | 2 +- src/components/dashboard/DashboardSidebar.tsx | 39 +++++- 3 files changed, 98 insertions(+), 60 deletions(-) diff --git a/src/components/dashboard/DashboardLayout.tsx b/src/components/dashboard/DashboardLayout.tsx index 6d89a037..a095b787 100644 --- a/src/components/dashboard/DashboardLayout.tsx +++ b/src/components/dashboard/DashboardLayout.tsx @@ -121,68 +121,73 @@ export function DashboardLayout({ } /> )} -
+
- {userSite.data?.[0]?.username && - subdomain && - userSite.data[0].username !== subdomain && ( -
-
You are operating
- - - {site.data?.name} - - @{site.data?.username} - - + {(isOpen) => ( + <> + {userSite.data?.[0]?.username && + subdomain && + userSite.data[0].username !== subdomain && ( +
+
You are operating
+ + + {site.data?.name} + + @{site.data?.username} + + +
+ )} +
+
- )} -
- -
-
- {links.map((link) => { - const active = - link.href && - link.isActive({ - pathname: router.asPath, - href: link.href, - }) - return ( +
+ {links.map((link) => { + const active = + link.href && + link.isActive({ + pathname: router.asPath, + href: link.href, + }) + return ( + + + {isOpen && {link.text}} + + ) + })} +
+ +
- - {link.text} + + {isOpen && View Site} - ) - })} -
- -
- - - View Site - -
+
+ + )} {children}
diff --git a/src/components/dashboard/DashboardMain.tsx b/src/components/dashboard/DashboardMain.tsx index 13c405a3..456a9bcc 100644 --- a/src/components/dashboard/DashboardMain.tsx +++ b/src/components/dashboard/DashboardMain.tsx @@ -5,7 +5,7 @@ export const DashboardMain: React.FC<{ fullWidth?: boolean }> = ({ children, fullWidth }) => { return ( -
+
React.ReactNode }> = ({ children }) => { + const [isOpen, setIsOpen] = useState(true) + + useEffect(() => { + const storage = getStorage("sidebar") + if (storage) { + setIsOpen(storage.isOpen) + } + }, []) + + useEffect(() => { + setStorage("sidebar", { + isOpen, + }) + }, [isOpen]) + return ( -
- {children} +
+ {children(isOpen)}
+
setIsOpen(!isOpen)} + > + {isOpen ? ( + + ) : ( + + )} +
) }