Skip to content

Commit

Permalink
prevent sidebar disappearing when in modal
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Nov 7, 2023
1 parent f970e78 commit 8dd809f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/components/layouts/interior-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import SideNav from "@components/menu/side-nav";
import {PropsWithChildren} from "react";
import {isDraftMode} from "@lib/drupal/utils";

const InteriorPage = async ({children}: PropsWithChildren<any>) => {
const InteriorPage = async ({children, currentPath}: PropsWithChildren<{ currentPath: string }>) => {
const draftDev = isDraftMode();
const {tree} = await getMenu('main', {}, draftDev);

return (
<div className="centered flex gap-20">
<SideNav menuItems={tree}/>
<SideNav menuItems={tree} currentPath={currentPath}/>
<article className="flex-grow">
{children}
</article>
Expand Down
18 changes: 2 additions & 16 deletions src/components/menu/side-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,8 @@ import useActiveTrail from "@lib/hooks/useActiveTrail";
import Link from "@components/elements/link";
import {DrupalMenuLinkContent} from "next-drupal";

const getCurrentPageTitle = (activeTrail: string[], items: DrupalMenuLinkContent[], trail: string[]): string | undefined => {
const currentItem = items.find(item => item.id === trail.at(0));
if (!currentItem || currentItem === undefined) return;

if (currentItem.id === activeTrail.at(-1)) {
return currentItem.title;
}

if (currentItem.items && currentItem.items.length > 0 && trail.length > 1) {
return getCurrentPageTitle(activeTrail, currentItem.items, trail.slice(1));
}
}


const SideNav = ({menuItems}: { menuItems: DrupalMenuLinkContent[] }) => {
const activeTrail = useActiveTrail(menuItems);
const SideNav = ({menuItems, currentPath}: { menuItems: DrupalMenuLinkContent[], currentPath?: string }) => {
const activeTrail = useActiveTrail(menuItems, currentPath);

// Peel off the menu items from the parent.
const topMenuItem = activeTrail.length > 0 ? menuItems.find(item => item.id === activeTrail[0]) : false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const StanfordPagePage = ({node}: { node: BasicPageNodeType }) => {
</H1>

{!fullWidth &&
<InteriorPage>
<InteriorPage currentPath={node.path.alias}>
{node.su_page_components &&
<Rows components={node.su_page_components}/>
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/hooks/useActiveTrail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {usePathname} from "next/navigation";
import {useMemo} from "react";
import {DrupalMenuLinkContent} from "next-drupal";

const useActiveTrail = (menuItems: DrupalMenuLinkContent[]) => {
const currentPath = usePathname();
const useActiveTrail = (menuItems: DrupalMenuLinkContent[], originalPath?: string) => {
const pathName = usePathname();
const currentPath = originalPath || pathName;

const getActiveTrail = (menuItems: DrupalMenuLinkContent[], trail: string[] = []): string[] => {
let childTrail, currentTrail;
Expand Down

1 comment on commit 8dd809f

@vercel
Copy link

@vercel vercel bot commented on 8dd809f Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.