From c0ceb2313e498f4567ad9d1072efd67debf8bb3d Mon Sep 17 00:00:00 2001 From: Wes Date: Mon, 30 Oct 2023 11:39:56 -0700 Subject: [PATCH] feat: make navigation bar collapsible (#527) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ![Screenshot 2023-10-30 at 11 35 38 AM](https://github.com/TBD54566975/ftl/assets/51647/dea16420-1d16-4639-b479-5231654bb29e) ![Screenshot 2023-10-30 at 11 35 41 AM](https://github.com/TBD54566975/ftl/assets/51647/622cb1d7-93ee-4812-a94a-aed615027979) --- console/client/src/hooks/use-local-storage.ts | 13 ++-- console/client/src/layout/Layout.tsx | 8 ++- .../src/layout/navigation/Navigation.tsx | 60 ++++++++++++++----- .../src/providers/dark-mode-provider.tsx | 8 +-- 4 files changed, 60 insertions(+), 29 deletions(-) diff --git a/console/client/src/hooks/use-local-storage.ts b/console/client/src/hooks/use-local-storage.ts index 8085a7b5cd..9fdd563103 100644 --- a/console/client/src/hooks/use-local-storage.ts +++ b/console/client/src/hooks/use-local-storage.ts @@ -1,12 +1,9 @@ -import React, { useEffect, useState } from 'react' +import { useEffect, useState } from 'react' -export default function useLocalStorage( - key: string, - initialValue: string, -): [string, React.Dispatch>] { - const [value, setValue] = useState(() => { +export default function useLocalStorage(key: string, initialValue: T) { + const [value, setValue] = useState(() => { const jsonValue = localStorage.getItem(key) - if (jsonValue != null) return JSON.parse(jsonValue) as string + if (jsonValue != null) return JSON.parse(jsonValue) as T return initialValue }) @@ -14,5 +11,5 @@ export default function useLocalStorage( localStorage.setItem(key, JSON.stringify(value)) }, [key, value]) - return [value, setValue] + return [value, setValue] as const } diff --git a/console/client/src/layout/Layout.tsx b/console/client/src/layout/Layout.tsx index 407ddaac37..7c205b4b62 100644 --- a/console/client/src/layout/Layout.tsx +++ b/console/client/src/layout/Layout.tsx @@ -1,6 +1,7 @@ import { Bars3Icon } from '@heroicons/react/24/outline' import { useState } from 'react' import { Outlet } from 'react-router-dom' +import useLocalStorage from '../hooks/use-local-storage' import { bgColor, textColor } from '../utils' import { Notification } from './Notification' import { SidePanel } from './SidePanel' @@ -9,6 +10,7 @@ import { Navigation } from './navigation/Navigation' export const Layout = () => { const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false) + const [isCollapsed, setIsCollapsed] = useLocalStorage('isNavCollapsed', false) return ( <> @@ -17,9 +19,11 @@ export const Layout = () => {