mohammed-ahad

nav3

May 12th, 2023
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { FC } from "react";
  2. import { UseQueryResult } from "react-query";
  3. import { useLocation, useNavigate } from "react-router-dom";
  4.  
  5. import MobileUserMenu from "./components/MobileUserMenu";
  6. import UserMenu from "./components/UserMenu";
  7. import navigation2 from "../.././config/navigation2";
  8. import { NavigationSchema2 } from "../../types";
  9. import ThemeToggle from "./components/ThemeToggle";
  10.  
  11. import {
  12.   LinkItem,
  13.   NavigationFooter,
  14.   NavigationHeader,
  15.   NestableNavigationContent,
  16.   NestingItem,
  17.   Section,
  18.   SideNavigation,
  19. } from "@atlaskit/side-navigation";
  20.  
  21. import { UserI } from "../../types";
  22.  
  23. interface PropsI {
  24.   logout: () => void;
  25.   user: UseQueryResult<UserI, any>;
  26.   avatar: UseQueryResult<Blob, any>;
  27.   theme: string;
  28.   setTheme: (theme: string) => void;
  29. }
  30.  
  31. const Nav3: FC<PropsI> = ({ logout, user, avatar, theme, setTheme }) => {
  32.   const location = useLocation();
  33.   const navigate = useNavigate();
  34.  
  35.   // Function to render navigation items
  36.   const NavItem = ({
  37.     id,
  38.     title,
  39.     path,
  40.     iconBefore: Icon,
  41.     items,
  42.   }: NavigationSchema2) => {
  43.     const handleOnClick = (path: string | undefined) => {
  44.       if (path) {
  45.         navigate(path);
  46.       }
  47.     };
  48.  
  49.     if (items) {
  50.       return (
  51.         <NestingItem
  52.           key={id}
  53.           id={id.toString()}
  54.           title={title}
  55.           iconBefore={Icon ? <Icon size={40} /> : undefined}
  56.           onClick={() => handleOnClick(path)}
  57.         >
  58.           <Section title={title}>{items.map((item) => NavItem(item))}</Section>
  59.         </NestingItem>
  60.       );
  61.     }
  62.     return (
  63.       <LinkItem
  64.         key={id}
  65.         iconBefore={Icon ? <Icon size={40} /> : undefined}
  66.         isSelected={location.pathname === path}
  67.         onClick={() => handleOnClick(path)}
  68.       >
  69.         {title}
  70.       </LinkItem>
  71.     );
  72.   };
  73.   return (
  74.     <>
  75.       <div className="w-72 h-screen bg-neutral overflow-y-auto">
  76.         <SideNavigation label="project" testId="side-navigation">
  77.           <NavigationHeader>
  78.             <div className="flex justify-center">
  79.               <a href="/">
  80.                 <img
  81.                   className="h-14 w-auto"
  82.                   src="/images/main-logo.png"
  83.                   alt=""
  84.                 />
  85.               </a>
  86.             </div>
  87.             <div>
  88.               <UserMenu
  89.                 navType={1}
  90.                 className="hidden lg:block"
  91.                 userLoading={user.status === "loading"}
  92.                 user={user?.data}
  93.                 avatarLoading={avatar.status === "loading"}
  94.                 avatar={avatar?.data}
  95.                 logout={logout}
  96.               />
  97.               <MobileUserMenu
  98.                 className="block lg:hidden"
  99.                 userLoading={user.status === "loading"}
  100.                 user={user?.data}
  101.                 avatarLoading={avatar.status === "loading"}
  102.                 avatar={avatar?.data}
  103.                 logout={logout}
  104.               />
  105.             </div>
  106.           </NavigationHeader>
  107.           <div className="bg-neutral h-full w-full">
  108.             <NestableNavigationContent
  109.               initialStack={[]}
  110.               testId="nestable-navigation-content"
  111.             >
  112.               <div className="text-text-secondary hover:text-text-primary pt-2 px-0 py-0 rounded-sm overflow-y-auto">
  113.                 <Section>{navigation2.map((item) => NavItem(item))}</Section>
  114.               </div>
  115.             </NestableNavigationContent>
  116.           </div>
  117.           <NavigationFooter>
  118.             <div className="flex flex-row items-center">
  119.               <ThemeToggle
  120.                 className={"absolute bottom-6 right-3"}
  121.                 theme={theme}
  122.                 setTheme={setTheme}
  123.               />
  124.             </div>
  125.           </NavigationFooter>
  126.         </SideNavigation>
  127.       </div>
  128.     </>
  129.   );
  130. };
  131.  
  132. export default Nav3;
  133.  
Advertisement
Add Comment
Please, Sign In to add comment