Skip to content

Commit

Permalink
fix: Post go live nav tweaks 2 (#699)
Browse files Browse the repository at this point in the history
* fix: fix nav preproces

* Correct comment

* Remove unncessary deps

* Default to desktop
  • Loading branch information
AndyEPhipps authored Jan 24, 2025
1 parent 4e6ae91 commit 60ff6f0
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const HeaderNav2025 = ({
const { menuGroups } = navItems;
const [isExpandable, setIsExpandable] = useState(false);
const [openedSubMenu, setOpenedSubMenu] = useState({});
const [isNotDesktop, setIsNotDesktop] = useState(null);
const [isNotDesktop, setIsNotDesktop] = useState(false);
const [processedItems, setProcessedItems] = useState(null);
const [showMoreNav, setShowMoreNav] = useState(false);
let theseGroups = null;
Expand Down Expand Up @@ -53,16 +53,19 @@ const HeaderNav2025 = ({

// Process the nav items on initial mount:
useMemo(() => {
// Divide up nav items accordingly and determine breakpoint,
// assigned as local vars since useState won't be ready in time below:
// Divide up nav items accordingly
const theseItems = MoreNavPreProcess(menuGroups, characterLimit);
const notDesktop = window.innerWidth < breakpointValues.Nav;
setProcessedItems(theseItems);
}, [menuGroups, characterLimit]);

// Determine which nav we should use only once 'window' exists:
useEffect(() => {
const notDesktop = window.innerWidth < breakpointValues.Nav;
setIsNotDesktop(notDesktop);

// Use these flags to detemine if we render the More nav or not:
setShowMoreNav(!notDesktop && theseItems.moreNavGroups.length);
}, [menuGroups, characterLimit]);
setShowMoreNav(!notDesktop && processedItems.moreNavGroups.length);
}, [processedItems]);

// Attach eventListener on mount and after potential changes
// to showMoreNav triggered by a window resize:
Expand Down

0 comments on commit 60ff6f0

Please sign in to comment.