From bce9ca3b0fcd3b43d27218cd3d08199e87dde70a Mon Sep 17 00:00:00 2001 From: Carlos Andres Perez Ubeda Date: Mon, 18 Nov 2024 17:29:39 -0600 Subject: [PATCH] refactor: update responsive overlay and improve dashboard layout - Removed ResponsiveOverlay component. - Added ResetMiniNavOnResize component to handle mini nav visibility. - Updated dashboard layout to conditionally render navigation components. - Adjusted main content padding and enhanced layout styles. --- src/App.tsx | 2 +- .../ResetMiniNavOnResize.tsx | 28 ++++++++++ .../responsive-overlay/ResponsiveOverlay.tsx | 52 ------------------- src/components/responsive-overlay/index.ts | 2 +- src/layouts/dashboard/layout.tsx | 13 +++-- src/layouts/dashboard/main.tsx | 2 +- src/layouts/dashboard/nav-mini.tsx | 2 +- src/layouts/dashboard/nav-vertical.tsx | 20 ++++++- 8 files changed, 60 insertions(+), 61 deletions(-) create mode 100644 src/components/responsive-overlay/ResetMiniNavOnResize.tsx delete mode 100644 src/components/responsive-overlay/ResponsiveOverlay.tsx diff --git a/src/App.tsx b/src/App.tsx index 2ee92464..c521bbb2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -77,7 +77,7 @@ export default function App() { - {/**/} + diff --git a/src/components/responsive-overlay/ResetMiniNavOnResize.tsx b/src/components/responsive-overlay/ResetMiniNavOnResize.tsx new file mode 100644 index 00000000..dd4b4094 --- /dev/null +++ b/src/components/responsive-overlay/ResetMiniNavOnResize.tsx @@ -0,0 +1,28 @@ +import { useState, useEffect } from 'react'; +import {useSettingsContext} from "@src/components/settings"; + +const ResetMiniNavOnResize = () => { + const [isSmallScreen, setIsSmallScreen] = useState(false); + const settings = useSettingsContext(); + + useEffect(() => { + const handleResize = () => { + setIsSmallScreen(window.innerWidth < 1200); + }; + + window.addEventListener('resize', handleResize); + handleResize(); + + return () => window.removeEventListener('resize', handleResize); + }, []); + + if(isSmallScreen && settings.themeLayout === 'mini') { + settings.onUpdate('themeLayout', 'vertical'); + } + + if (!isSmallScreen) { + return null; + } +}; + +export default ResetMiniNavOnResize; diff --git a/src/components/responsive-overlay/ResponsiveOverlay.tsx b/src/components/responsive-overlay/ResponsiveOverlay.tsx deleted file mode 100644 index 43dc9cc7..00000000 --- a/src/components/responsive-overlay/ResponsiveOverlay.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import { useState, useEffect } from 'react'; -import { Box, Typography } from '@mui/material'; -import Image from "@src/components/image"; -import responsiveImage from '@public/assets/illustrations/working-responsive.png'; - -const ResponsiveOverlay = () => { - const [isSmallScreen, setIsSmallScreen] = useState(false); - - useEffect(() => { - const handleResize = () => { - setIsSmallScreen(window.innerWidth < 1200); - }; - - window.addEventListener('resize', handleResize); - handleResize(); - - return () => window.removeEventListener('resize', handleResize); - }, []); - - if (!isSmallScreen) { - return null; - } - - return ( - - - Watchit App - - Watchit App - - We are working on making this page responsive. - - - ); -}; - -export default ResponsiveOverlay; diff --git a/src/components/responsive-overlay/index.ts b/src/components/responsive-overlay/index.ts index fafd0f08..6d2f49b9 100644 --- a/src/components/responsive-overlay/index.ts +++ b/src/components/responsive-overlay/index.ts @@ -1 +1 @@ -export { default as ResponsiveOverlay } from './ResponsiveOverlay.tsx'; +export { default as ResponsiveOverlay } from './ResetMiniNavOnResize.tsx'; diff --git a/src/layouts/dashboard/layout.tsx b/src/layouts/dashboard/layout.tsx index f391bfc3..b55d4bfa 100644 --- a/src/layouts/dashboard/layout.tsx +++ b/src/layouts/dashboard/layout.tsx @@ -54,7 +54,6 @@ export default function DashboardLayout({ children }: Props) { return ( <>
- - {renderNavVertical} - + { + lgUp + ? renderNavVertical + : ( + + ) + }
{children}
diff --git a/src/layouts/dashboard/main.tsx b/src/layouts/dashboard/main.tsx index 00edebc2..b4e29dca 100644 --- a/src/layouts/dashboard/main.tsx +++ b/src/layouts/dashboard/main.tsx @@ -18,7 +18,7 @@ export default function Main({ children, sx, ...other }: BoxProps) { - {renderContent} + + + + + + {renderContent} + + + + )}