@@ -2,7 +2,7 @@ import React, { useMemo } from "react";
2
2
import styled , { css } from "styled-components" ;
3
3
import { landscapeStyle } from "styles/landscapeStyle" ;
4
4
5
- import { Link , useLocation } from "react-router-dom" ;
5
+ import { Link , useLocation , useSearchParams } from "react-router-dom" ;
6
6
import { useAccount } from "wagmi" ;
7
7
8
8
import { useOpenContext } from "../MobileHeader" ;
@@ -57,8 +57,9 @@ interface IExplore {
57
57
58
58
const Explore : React . FC < IExplore > = ( { isMobileNavbar } ) => {
59
59
const location = useLocation ( ) ;
60
+ const [ searchParams ] = useSearchParams ( ) ;
60
61
const { toggleIsOpen } = useOpenContext ( ) ;
61
- const { isConnected, address } = useAccount ( ) ;
62
+ const { isConnected } = useAccount ( ) ;
62
63
63
64
const navLinks = useMemo ( ( ) => {
64
65
const base = [
@@ -68,24 +69,31 @@ const Explore: React.FC<IExplore> = ({ isMobileNavbar }) => {
68
69
{ to : "/jurors/1/desc/all" , text : "Jurors" } ,
69
70
{ to : "/get-pnk" , text : "Get PNK" } ,
70
71
] ;
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" } ) ;
73
74
}
74
75
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
+ } ;
76
88
77
89
return (
78
90
< Container >
79
91
< 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
+ ) ) }
89
97
</ Container >
90
98
) ;
91
99
} ;
0 commit comments