@@ -2,7 +2,7 @@ import React, { useMemo } from "react";
22import styled , { css } from "styled-components" ;
33import { landscapeStyle } from "styles/landscapeStyle" ;
44
5- import { Link , useLocation } from "react-router-dom" ;
5+ import { Link , useLocation , useSearchParams } from "react-router-dom" ;
66import { useAccount } from "wagmi" ;
77
88import { useOpenContext } from "../MobileHeader" ;
@@ -57,8 +57,9 @@ interface IExplore {
5757
5858const Explore : React . FC < IExplore > = ( { isMobileNavbar } ) => {
5959 const location = useLocation ( ) ;
60+ const [ searchParams ] = useSearchParams ( ) ;
6061 const { toggleIsOpen } = useOpenContext ( ) ;
61- const { isConnected, address } = useAccount ( ) ;
62+ const { isConnected } = useAccount ( ) ;
6263
6364 const navLinks = useMemo ( ( ) => {
6465 const base = [
@@ -68,24 +69,31 @@ const Explore: React.FC<IExplore> = ({ isMobileNavbar }) => {
6869 { to : "/jurors/1/desc/all" , text : "Jurors" } ,
6970 { to : "/get-pnk" , text : "Get PNK" } ,
7071 ] ;
71- if ( isConnected && address ) {
72- base . push ( { to : ` /profile/1/desc/all?address= ${ address } ` , text : "My Profile" } ) ;
72+ if ( isConnected ) {
73+ base . push ( { to : " /profile/1/desc/all" , text : "My Profile" } ) ;
7374 }
7475 return base ;
75- } , [ isConnected , address ] ) ;
76+ } , [ isConnected ] ) ;
77+
78+ const currentSeg = useMemo ( ( ) => location . pathname . split ( "/" ) [ 1 ] || "" , [ location . pathname ] ) ;
79+ const ownsProfile = ! searchParams . get ( "address" ) ;
80+
81+ const getIsActive = ( to : string ) => {
82+ const path = to . split ( "?" ) [ 0 ] ;
83+ if ( path === "/" ) return location . pathname === "/" ;
84+ const targetSeg = path . split ( "/" ) [ 1 ] || "" ;
85+ if ( targetSeg !== currentSeg ) return false ;
86+ return targetSeg !== "profile" || ownsProfile ;
87+ } ;
7688
7789 return (
7890 < Container >
7991 < Title > Explore</ Title >
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- } ) }
92+ { navLinks . map ( ( { to, text } ) => (
93+ < StyledLink key = { text } onClick = { toggleIsOpen } isActive = { getIsActive ( to ) } { ...{ to, isMobileNavbar } } >
94+ { text }
95+ </ StyledLink >
96+ ) ) }
8997 </ Container >
9098 ) ;
9199} ;
0 commit comments