Skip to content

Commit

Permalink
easy
Browse files Browse the repository at this point in the history
  • Loading branch information
0-don committed May 19, 2024
1 parent 0de95e0 commit 0d4a2aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
20 changes: 6 additions & 14 deletions web/src/components/container/navbar/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,27 @@ import { MyLink } from "@/components/elements/MyLink";
import { useMeHook } from "@/components/hooks/useMeHook";
import { usePathname } from "@/navigation";
import { getMenu } from "@/utils/helpers/clientUtils";
import { MenuType } from "@/utils/types";
import {
NavbarContent,
NavbarItem,
NavbarMenu,
NavbarMenuItem,
} from "@nextui-org/navbar";
import { useTranslations } from "next-intl";
import React, { useEffect, useState } from "react";
import React from "react";

interface MainMenuProps {
pathname: string;
}
interface MainMenuProps {}

export const MainMenu: React.FC<MainMenuProps> = ({ pathname }) => {
export const MainMenu: React.FC<MainMenuProps> = ({}) => {
const t = useTranslations<"Navbar">();
const { me } = useMeHook();
const roles = me?.userRole?.map((role) => role.name) || [];
const p = usePathname();
const [path, setPath] = useState<string>(pathname || p);
const [links, setLinks] = useState<MenuType[]>(getMenu(roles));

useEffect(() => void setPath(p || pathname), [pathname, p]);
useEffect(() => void setLinks(getMenu(roles)), [me]);
const path = usePathname();

return (
<>
<NavbarContent className="hidden gap-4 sm:flex">
{links.map(({ link, name }) => (
{getMenu(roles).map(({ link, name }) => (
<NavbarItem
key={link}
isActive={path === link}
Expand All @@ -45,7 +37,7 @@ export const MainMenu: React.FC<MainMenuProps> = ({ pathname }) => {
))}
</NavbarContent>
<NavbarMenu>
{links.map(({ link, name }) => (
{getMenu(roles).map(({ link, name }) => (
<NavbarMenuItem key={link} isActive={path === link}>
<MyLink href={link} size="lg" className="!font-bold">
{t(name as keyof Messages["Navbar"])}
Expand Down
5 changes: 2 additions & 3 deletions web/src/components/container/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LanguageSwitch } from "@/components/utils/LanguageSwitch";
import { ThemeSwitch } from "@/components/utils/ThemeSwitch";
import { ME } from "@/documents/query/auth";
import { LOCALES } from "@/middleware";
import { prefetchQuery, ssrUrl } from "@/utils/helpers/serverComponentsUtil";
import { prefetchQuery } from "@/utils/helpers/serverComponentsUtil";
import { Link } from "@nextui-org/link";
import {
NavbarBrand,
Expand All @@ -23,7 +23,6 @@ interface NavbarProps {}
export const Navbar: React.FC<NavbarProps> = async ({}) => {
const { state } = await prefetchQuery([{ document: ME }]);
const locale = cookies().get("NEXT_LOCALE")?.value || LOCALES[0];
const pathname = ssrUrl().pathname;

const Items = (
<>
Expand Down Expand Up @@ -69,7 +68,7 @@ export const Navbar: React.FC<NavbarProps> = async ({}) => {
</Link>
</NavbarBrand>

<MainMenu pathname={pathname} />
<MainMenu />

<NavbarContent
className="hidden basis-1/5 sm:flex sm:basis-full"
Expand Down

0 comments on commit 0d4a2aa

Please sign in to comment.