Skip to content

Commit f5c31da

Browse files
committed
fix: Link && TextButton compatibility
1 parent f0d5483 commit f5c31da

File tree

50 files changed

+135
-106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+135
-106
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"warn",
5151
{
5252
"args": "none",
53+
"varsIgnorePattern": "^_error$",
5354
"ignoreRestSiblings": true
5455
}
5556
],

src/app/_components/BuildWithScroll/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client"
22

3-
import Img from "react-cool-img"
3+
import Image from "next/image"
44

55
import { Stack, SvgIcon, Typography } from "@mui/material"
66
import { Button as MuiButton } from "@mui/material"
@@ -36,7 +36,7 @@ const Feature = () => {
3636
return (
3737
<OrientationToView key={feature.title}>
3838
<Stack key={featureIdx} direction="column" spacing="2.4rem" sx={{ maxWidth: "56rem" }}>
39-
<Img src={feature.icon} width={isMobile ? 320 : 400}></Img>
39+
<Image src={feature.icon} alt={feature.title} width={isMobile ? 320 : 400} height={isMobile ? 320 : 400}></Image>
4040
<Typography sx={{ fontSize: ["2rem", "2.4rem"], fontWeight: 600 }}>{feature.title}</Typography>
4141
<Typography sx={{ fontSize: ["1.6rem", "2rem"], mt: ["0.8rem !important", 0] }}>{feature.description}</Typography>
4242
<MuiButton

src/app/_components/ExploreEcosystem/Carousel.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Image from "next/image"
2+
13
import { Box } from "@mui/material"
24
import { keyframes, styled } from "@mui/system"
35

@@ -172,7 +174,7 @@ const TrackRight = styled("div")(({ theme }) => ({
172174
width: "max-content",
173175
}))
174176

175-
const Logo = styled("img")(({ theme }) => ({
177+
const Logo = styled(Image)(({ theme }) => ({
176178
width: "8.8rem",
177179
height: "8.8rem",
178180
marginRight: "10rem",

src/app/blog/[blogId]/detail.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const BlogDetail = () => {
8181
setLoading(false)
8282
setBlogContent(text)
8383
})
84-
} catch (error) {
84+
} catch (_error) {
8585
router.push("/404")
8686
}
8787
} else if (blogIdMatch && language === "en") {

src/app/bridge/Send/SendTransaction/TokenList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Dialog from "@mui/material/Dialog"
99
import DialogTitle from "@mui/material/DialogTitle"
1010
import ListItemText from "@mui/material/ListItemText"
1111

12-
import { tokenList } from "@/app/sessions-one/SessionZeroMarks/tokenList"
12+
import { tokenList } from "@/app/sessions/SessionZeroMarks/tokenList"
1313
import CloseSvg from "@/assets/svgs/bridge/token-list-close.svg"
1414
import SearchSvg from "@/assets/svgs/bridge/token-list-search.svg"
1515
import { EXPLORER_URL } from "@/constants"

src/app/bridge/components/TxTable/ActiveButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const ActiveButton = props => {
7171
try {
7272
// cancel switch network in MetaMask would not throw error and the result is null just like successfully switched
7373
await switchNetwork(chainId)
74-
} catch (error) {
74+
} catch (_error) {
7575
// when there is a switch-network popover in MetaMask and refreshing page would throw an error
7676
}
7777
}

src/app/canvas/badge/[id]/Badge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const Badge = () => {
111111
badgeDetail.rarity = NFT_RARITY_MAP[rarityNum]
112112
}
113113
setDetail(badgeDetail)
114-
} catch (e) {
114+
} catch (_error) {
115115
alertWarning("Failed to fetch badge detail")
116116
} finally {
117117
setLoading(false)

src/app/canvas/mint/home/ReferralCodeInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const ReferralCode = ({ isChecking, setIsChecking, code, codeStatus, setCodeStat
124124
changeReferralCode("")
125125
setCodeStatus(CodeStatus.INVALID)
126126
}
127-
} catch (e) {
127+
} catch (_error) {
128128
changeReferralCode("")
129129
setCodeStatus(CodeStatus.ERROR)
130130
inputRefs.current[INVITE_CODE_LENGTH - 1]?.focus()

src/app/developer-nft/mint/home/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const MintHome = () => {
4545
const totalSupply = await fetchTotalSupply(instance)
4646
const totalSupply2 = await fetchTotalSupply(instance2)
4747
setMintedAmount(totalSupply + totalSupply2)
48-
} catch (e) {
48+
} catch (_error) {
4949
} finally {
5050
setLoading(false)
5151
}

src/app/ecosystem/Protocols/ProtocolList/ProtocolCard.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,7 @@ const ProtocolCard = props => {
167167
>
168168
{name}
169169
</Typography>
170-
<Link
171-
external
172-
href={TWITTER_ORIGIN + twitterHandle}
173-
sx={{
174-
color: "inherit",
175-
"&:hover": {
176-
color: theme => (theme as any).vars.palette.primary.main,
177-
},
178-
}}
179-
>
170+
<Link external href={TWITTER_ORIGIN + twitterHandle} undefined="hover" className="text-inherit hover:text-[var(--mui-palette-link-main)]">
180171
<SvgIcon sx={{ fontSize: "1.4rem" }} component={TwitterSvg} inheritViewBox></SvgIcon>
181172
</Link>
182173
{isDesktop && (
@@ -223,7 +214,7 @@ const ProtocolCard = props => {
223214
</Box>
224215
)}
225216
<Button
226-
href={website}
217+
href={website ?? ""}
227218
target="_blank"
228219
classes={{ root: classes.action }}
229220
endIcon={<SvgIcon sx={{ fontSize: ["1.2rem !important", "1.4rem !important"] }} component={ArrowSvg} inheritViewBox></SvgIcon>}

src/app/ecosystem/Protocols/ProtocolList/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import useScrollTrigger from "@mui/material/useScrollTrigger"
99
import { keyframes } from "@mui/system"
1010

1111
import { ecosystemListUrl } from "@/apis/ecosystem"
12-
import Link from "@/components/Link"
1312
import LoadingButton from "@/components/LoadingButton"
1413
import LoadingPage from "@/components/LoadingPage"
14+
import TextButton from "@/components/TextButton"
1515
import { ECOSYSTEM_NETWORK_LIST } from "@/constants"
1616
import { isAboveScreen } from "@/utils/dom"
1717

@@ -168,7 +168,7 @@ const ProtocolList = props => {
168168

169169
{hasMore && (
170170
<Box sx={{ gridColumn: ["1 / 3", "1 / 3", "2 / 4"], textAlign: "center", mt: "1.6rem" }}>
171-
<Link
171+
<TextButton
172172
underline="always"
173173
component="button"
174174
sx={{
@@ -182,7 +182,7 @@ const ProtocolList = props => {
182182
onClick={onAddPage}
183183
>
184184
Load more
185-
</Link>
185+
</TextButton>
186186
</Box>
187187
)}
188188
</>

src/app/layout.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export default function RootLayout({ children }: { children: React.ReactNode })
7676
</head>
7777
<body>
7878
<AppRouterCacheProvider options={{ key: "css" }}>
79-
{/* <NextAppDirEmotionCacheProvider > */}
8079
<ScrollThemeProvider>
8180
<VersionChecker>
8281
<RainbowProvider>
@@ -88,7 +87,6 @@ export default function RootLayout({ children }: { children: React.ReactNode })
8887
</VersionChecker>
8988
<ScrollToTop />
9089
</ScrollThemeProvider>
91-
{/* </NextAppDirEmotionCacheProvider> */}
9290
</AppRouterCacheProvider>
9391
{process.env.NODE_ENV === "production" && (
9492
<>

src/app/portal/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use client"
2+
13
import { Box, Container, Stack, Typography } from "@mui/material"
24

35
import { L2_NAME } from "@/constants"
File renamed without changes.

src/assets/svgs/footer/github.svg

Lines changed: 1 addition & 1 deletion
Loading

src/components/Header/SubmenuLink.tsx

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { default as NavLink } from "next/link"
21
import ReactGA from "react-ga4"
32

4-
import { Box, Link, Stack, SvgIcon, Typography } from "@mui/material"
3+
import { Box, Stack, SvgIcon, Typography } from "@mui/material"
54
import { CSSObject, Theme, styled } from "@mui/material/styles"
65

76
import ExternalSvg from "@/assets/svgs/header/External.svg"
7+
import Link from "@/components/Link"
88
import useCheckViewport from "@/hooks/useCheckViewport"
99

1010
const linkStyles = (theme: Theme, dark: boolean): CSSObject => ({
@@ -40,19 +40,10 @@ interface StyledNavLinkProps {
4040
reloadDocument?: boolean
4141
}
4242

43-
interface StyledLinkProps {
44-
dark?: boolean
45-
href?: string
46-
}
47-
48-
const StyledNavLink = styled(NavLink, {
43+
const StyledNavLink = styled(Link, {
4944
shouldForwardProp: prop => prop !== "dark",
5045
})<StyledNavLinkProps>(({ theme, dark }) => linkStyles(theme, !!dark))
5146

52-
const StyledLink = styled(Link, {
53-
shouldForwardProp: prop => prop !== "dark",
54-
})<StyledLinkProps>(({ theme, dark }) => linkStyles(theme, !!dark))
55-
5647
const SubmenuLinkContent = ({ icon, label, text, isExternal }: { icon: any; label: string; text?: string; isExternal?: boolean }) => {
5748
const { isDesktop } = useCheckViewport()
5849

@@ -96,6 +87,7 @@ const SubmenuLink = ({
9687
icon,
9788
dark,
9889
reload,
90+
className,
9991
onClick,
10092
}: {
10193
label: string
@@ -105,18 +97,13 @@ const SubmenuLink = ({
10597
icon?: any
10698
dark?: boolean
10799
reload?: boolean
100+
className?: string
108101
onClick?: () => {}
109102
}) => (
110103
<>
111-
{isExternal ? (
112-
<StyledLink dark={dark} href={href} onClick={onClick} target="_blank" rel="noopener noreferrer">
113-
<SubmenuLinkContent icon={icon} label={label} text={text} isExternal={isExternal} />
114-
</StyledLink>
115-
) : (
116-
<StyledNavLink dark={dark} href={href} onClick={onClick} reloadDocument={reload}>
117-
<SubmenuLinkContent icon={icon} label={label} text={text} isExternal={isExternal} />
118-
</StyledNavLink>
119-
)}
104+
<StyledNavLink className={className} dark={dark} href={href} external={isExternal} reloadDocument={reload} onClick={onClick}>
105+
<SubmenuLinkContent icon={icon} label={label} text={text} isExternal={isExternal} />
106+
</StyledNavLink>
120107
</>
121108
)
122109

src/components/Header/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ const mainnetNavigations = [
250250
rootKey: "ecosystem",
251251
href: "/community",
252252
icon: CommunitySvg,
253-
reload: true,
254253
},
255254
],
256255
},

src/components/Header/desktop_header.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { default as NavLink } from "next/link"
1+
// import { default as NavLink } from "next/link"
22
import React, { useState } from "react"
33
import ReactGA from "react-ga4"
44
import { useStyles } from "tss-react/mui"
@@ -8,6 +8,7 @@ import { styled } from "@mui/material/styles"
88

99
import TriangleDownSvg from "@/assets/svgs/common/header-triangle-down.svg"
1010
import LanguageSelect from "@/components/LanguageSelect"
11+
import NavLink from "@/components/Link"
1112
import Logo from "@/components/ScrollLogo"
1213
import WalletToolkit from "@/components/WalletToolkit"
1314
import useCheckViewport from "@/hooks/useCheckViewport"
@@ -129,7 +130,8 @@ const SectionList = styled<any>(Box)(({ theme }) => ({
129130
},
130131
}))
131132

132-
const App = ({ currentMenu }) => {
133+
const DesktopHeader = ({ currentMenu }) => {
134+
console.log(currentMenu, "currentMenu")
133135
const { cx } = useStyles()
134136
const [isHover, setIsHover] = useState(false)
135137
const navbarBg = useCheckCustomNavBarBg({ isHover })
@@ -173,10 +175,15 @@ const App = ({ currentMenu }) => {
173175
}}
174176
>
175177
{section.children.map((item, index) => (
176-
<Stack key={item.label} direction="column" spacing="2.4rem" sx={{ gridRow: !index ? "1/3" : "unset", height: "min-content" }}>
178+
<Stack key={item.key} direction="column" spacing="2.4rem" sx={{ gridRow: !index ? "1/3" : "unset", height: "min-content" }}>
177179
<Typography sx={{ fontSize: "1.4rem", fontWeight: 700 }}>{item.label}</Typography>
178180
{item.items.map(item => (
179-
<SubmenuLink key={item.label} {...item} onClick={handleResetIsHover}></SubmenuLink>
181+
<SubmenuLink
182+
key={item.key}
183+
className={cx(item.key === currentMenu[0] && "active")}
184+
{...item}
185+
onClick={handleResetIsHover}
186+
></SubmenuLink>
180187
))}
181188
</Stack>
182189
))}
@@ -186,7 +193,14 @@ const App = ({ currentMenu }) => {
186193
{section.children
187194
// only show sub menu item when the href is set
188195
?.filter(subItem => subItem.href)
189-
.map(subItem => <SubmenuLink key={subItem.label} {...subItem} onClick={handleResetIsHover}></SubmenuLink>)}
196+
.map(subItem => (
197+
<SubmenuLink
198+
key={subItem.key}
199+
className={cx(subItem.key === currentMenu[0] && "active")}
200+
{...subItem}
201+
onClick={handleResetIsHover}
202+
></SubmenuLink>
203+
))}
190204
</>
191205
)}
192206
</SectionList>
@@ -200,7 +214,7 @@ const App = ({ currentMenu }) => {
200214
direction="row"
201215
alignItems="center"
202216
dark={dark}
203-
className={currentMenu === item.key ? "active" : ""}
217+
className={currentMenu.includes(item.key) ? "active" : ""}
204218
onMouseEnter={e => handleMouseEnter(e, item.key)}
205219
onMouseLeave={handleMouseLeave}
206220
>
@@ -236,7 +250,7 @@ const App = ({ currentMenu }) => {
236250
} else {
237251
return (
238252
<LinkStyledButton
239-
className={currentMenu === item.key ? "active" : ""}
253+
className={currentMenu.includes(item.key) ? "active" : ""}
240254
dark={dark}
241255
href={item.href}
242256
end={item.end}
@@ -293,4 +307,4 @@ const App = ({ currentMenu }) => {
293307
)
294308
}
295309

296-
export default App
310+
export default DesktopHeader

src/components/Header/index.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,30 @@ export default function Header() {
3939
const { isLandscape } = useCheckViewport()
4040
const pathname = usePathname()
4141

42-
const [currentMenu, setCurrentMenu] = useState("")
42+
const [currentMenu, setCurrentMenu] = useState<Array<string>>([])
4343

4444
useEffect(() => {
45-
const rootMenu = findRootMenu(pathname, navigations)
46-
setCurrentMenu(rootMenu ?? "")
45+
const rootMenu = findRootMenu(pathname, navigations, [])
46+
setCurrentMenu(rootMenu)
4747
}, [pathname])
4848

49-
const findRootMenu = (pathname, menuList: Array<any>) => {
49+
const findRootMenu = (pathname, menuList: Array<any>, result) => {
5050
for (const menuItem of menuList) {
5151
if (menuItem.href && pathname.includes(menuItem.href)) {
52-
return menuItem.rootKey || menuItem.key
53-
} else if (menuItem.children) {
54-
const key = findRootMenu(pathname, menuItem.children)
55-
if (key) {
56-
return key
52+
if (menuItem?.key) {
53+
result.push(menuItem.key as string)
54+
}
55+
if (menuItem?.rootKey) {
56+
result.push(menuItem.rootKey as string)
5757
}
58+
// return menuKey
59+
} else if (menuItem.children) {
60+
findRootMenu(pathname, menuItem.children, result)
61+
} else if (menuItem.items) {
62+
findRootMenu(pathname, menuItem.items, result)
5863
}
5964
}
60-
return null
65+
return result
6166
}
6267

6368
if (isLandscape) {

0 commit comments

Comments
 (0)