Skip to content

Commit

Permalink
Merge pull request #628 from markusgeert/fix/prevent-sidenav-flicker
Browse files Browse the repository at this point in the history
fix: prevent sidenav flicker
  • Loading branch information
rudivanhierden authored Nov 6, 2024
2 parents 35dbc35 + 7b727fe commit f073288
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions apps/admin-server/src/components/ui/page-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { Sidenav } from './sidenav';
import { SidenavProject } from './sidenav-project';
import { useRouter } from 'next/router';

function pathIsSpecificProject(pathname: string) {
return pathname.startsWith('/projects/[project]')
}

export function PageLayout({
children,
className,
Expand All @@ -19,25 +23,17 @@ export function PageLayout({
breadcrumbs: any;
action?: ReactNode;
}) {
const [openSideMenu, setOpenSideMenu] = useState(false);

const router = useRouter();
const [location, setLocation] = useState('');
const [hasProjectSidenav, setHasProjectSidenav] = useState(false);

useEffect(() => {
setHasProjectSidenav(location.startsWith('/projects/[project]'));
}, [location]);
const [hasProjectSidenav, setHasProjectSidenav] = useState(pathIsSpecificProject(router.pathname));

useEffect(() => {
setLocation(router.pathname);
setHasProjectSidenav(pathIsSpecificProject(router.pathname));
}, [router]);

return (
<main className="flex flex-row min-h-screen bg-muted">
<Sidenav
narrow={hasProjectSidenav}
className={openSideMenu ? 'translate-x-0' : ''}
/>
{hasProjectSidenav ? <SidenavProject /> : null}
<section className="col-span-full w-full">
Expand Down

0 comments on commit f073288

Please sign in to comment.