Skip to content

Commit

Permalink
fix(plus-menu): exclude AI Help from isActive state
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Nov 8, 2023
1 parent 0a1e556 commit 96ddc21
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions client/src/ui/molecules/plus-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useIsServer, useLocale, useViewedState } from "../../../hooks";
import { useUserData } from "../../../user-context";
import { MenuEntry } from "../submenu";
import { FeatureId } from "../../../constants";
import { useLocation } from "react-router";

export const PlusMenu = ({ visibleSubMenuId, toggleMenu }) => {
const plusUrl = usePlusUrl();
Expand All @@ -15,6 +16,13 @@ export const PlusMenu = ({ visibleSubMenuId, toggleMenu }) => {

const { isViewed } = useViewedState();

// Avoid that "Plus" and "AI Help" are both active.
const { pathname } = useLocation();
const aiHelpUrl = `/${locale}/plus/ai-help`;
const isActive =
pathname.startsWith(plusUrl.split("#", 2)[0]) &&
!pathname.startsWith(aiHelpUrl);

const plusMenu: MenuEntry = {
label: "Plus",
id: "mdn-plus",
Expand All @@ -32,7 +40,7 @@ export const PlusMenu = ({ visibleSubMenuId, toggleMenu }) => {
hasIcon: true,
iconClasses: "submenu-icon",
label: "AI Help (beta)",
url: `/${locale}/plus/ai-help`,
url: aiHelpUrl,
},
...(!isServer && isAuthenticated
? [
Expand Down Expand Up @@ -75,5 +83,12 @@ export const PlusMenu = ({ visibleSubMenuId, toggleMenu }) => {
};
const isOpen = visibleSubMenuId === plusMenu.id;

return <Menu menu={plusMenu} isOpen={isOpen} toggle={toggleMenu} />;
return (
<Menu
menu={plusMenu}
isActive={isActive}
isOpen={isOpen}
toggle={toggleMenu}
/>
);
};

0 comments on commit 96ddc21

Please sign in to comment.