|
1 |
| -import React from "react"; |
| 1 | +import React, { useMemo } from "react"; |
2 | 2 | import styled, { css } from "styled-components";
|
3 | 3 | import { landscapeStyle } from "styles/landscapeStyle";
|
4 | 4 |
|
5 | 5 | import { Link, useLocation } from "react-router-dom";
|
| 6 | +import { useAccount } from "wagmi"; |
6 | 7 |
|
7 | 8 | import { useOpenContext } from "../MobileHeader";
|
8 | 9 |
|
@@ -50,35 +51,41 @@ const StyledLink = styled(Link)<{ isActive: boolean; isMobileNavbar?: boolean }>
|
50 | 51 | )};
|
51 | 52 | `;
|
52 | 53 |
|
53 |
| -const links = [ |
54 |
| - { to: "/", text: "Home" }, |
55 |
| - { to: "/cases/display/1/desc/all", text: "Cases" }, |
56 |
| - { to: "/courts", text: "Courts" }, |
57 |
| - { to: "/jurors/1/desc/all", text: "Jurors" }, |
58 |
| - { to: "/get-pnk", text: "Get PNK" }, |
59 |
| -]; |
60 |
| - |
61 | 54 | interface IExplore {
|
62 | 55 | isMobileNavbar?: boolean;
|
63 | 56 | }
|
64 | 57 |
|
65 | 58 | const Explore: React.FC<IExplore> = ({ isMobileNavbar }) => {
|
66 | 59 | const location = useLocation();
|
67 | 60 | const { toggleIsOpen } = useOpenContext();
|
| 61 | + const { isConnected, address } = useAccount(); |
| 62 | + |
| 63 | + const navLinks = useMemo(() => { |
| 64 | + const base = [ |
| 65 | + { to: "/", text: "Home" }, |
| 66 | + { to: "/cases/display/1/desc/all", text: "Cases" }, |
| 67 | + { to: "/courts", text: "Courts" }, |
| 68 | + { to: "/jurors/1/desc/all", text: "Jurors" }, |
| 69 | + { to: "/get-pnk", text: "Get PNK" }, |
| 70 | + ]; |
| 71 | + if (isConnected && address) { |
| 72 | + base.push({ to: `/profile/1/desc/all?address=${address}`, text: "My Profile" }); |
| 73 | + } |
| 74 | + return base; |
| 75 | + }, [isConnected, address]); |
68 | 76 |
|
69 | 77 | return (
|
70 | 78 | <Container>
|
71 | 79 | <Title>Explore</Title>
|
72 |
| - {links.map(({ to, text }) => ( |
73 |
| - <StyledLink |
74 |
| - key={text} |
75 |
| - onClick={toggleIsOpen} |
76 |
| - isActive={to === "/" ? location.pathname === "/" : location.pathname.split("/")[1] === to.split("/")[1]} |
77 |
| - {...{ to, isMobileNavbar }} |
78 |
| - > |
79 |
| - {text} |
80 |
| - </StyledLink> |
81 |
| - ))} |
| 80 | + {navLinks.map(({ to, text }) => { |
| 81 | + const pathBase = to.split("?")[0]; |
| 82 | + const isActive = pathBase === "/" ? location.pathname === "/" : location.pathname.startsWith(pathBase); |
| 83 | + return ( |
| 84 | + <StyledLink key={text} onClick={toggleIsOpen} isActive={isActive} {...{ to, isMobileNavbar }}> |
| 85 | + {text} |
| 86 | + </StyledLink> |
| 87 | + ); |
| 88 | + })} |
82 | 89 | </Container>
|
83 | 90 | );
|
84 | 91 | };
|
|
0 commit comments