Skip to content

Commit c9b870e

Browse files
committed
fix: prevent reusing same link on sidebar
1 parent 6f0a780 commit c9b870e

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

apps/namadillo/src/App/Common/SidebarMenuItem.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import clsx from "clsx";
2-
import { NavLink } from "react-router-dom";
2+
import { NavLink, useLocation } from "react-router-dom";
33

44
type Props = {
55
url?: string;
66
children: React.ReactNode;
77
shouldHighlight?: boolean;
8+
preventNavigationOnSameRoute?: boolean;
89
};
910

1011
export const SidebarMenuItem = ({
1112
url,
1213
children,
1314
shouldHighlight,
15+
preventNavigationOnSameRoute = false,
1416
}: Props): JSX.Element => {
17+
const location = useLocation();
18+
1519
const className = clsx(
1620
"flex items-center gap-5 text-lg text-white",
1721
"transition-colors duration-300 ease-out-quad hover:text-cyan",
@@ -24,9 +28,16 @@ export const SidebarMenuItem = ({
2428
return <span className={className}>{children}</span>;
2529
}
2630

31+
const handleClick = (e: React.MouseEvent): void => {
32+
if (preventNavigationOnSameRoute && location.pathname === url) {
33+
e.preventDefault();
34+
}
35+
};
36+
2737
return (
2838
<NavLink
2939
to={url}
40+
onClick={handleClick}
3041
className={({ isActive }) =>
3142
clsx(className, {
3243
"text-yellow font-bold": isActive || shouldHighlight,

apps/namadillo/src/App/Layout/Navigation.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ export const Navigation = (): JSX.Element => {
9999
shouldHighlight={
100100
!!highlightTransferItem || !!highlightShieldItem
101101
}
102+
preventNavigationOnSameRoute={
103+
(item.label === "Shield" && highlightShieldItem) ||
104+
(item.label === "Transfer" && highlightTransferItem)
105+
}
102106
>
103107
{item.icon}
104108
{item.label}

apps/namadillo/src/App/Transfer/TransferSource.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ export const TransferSource = ({
8888
return (
8989
<div
9090
className={clsx(
91-
"relative bg-neutral-800 rounded-lg px-4 py-5 border-2",
92-
selectedTokenType === "shielded" ? "border-yellow-400" : "border-white"
91+
"relative bg-neutral-800 rounded-lg px-4 py-5",
92+
asset && "border",
93+
asset && selectedTokenType === "shielded" ?
94+
"border-yellow-400"
95+
: asset && "border-white"
9396
)}
9497
>
9598
<header className="relative flex justify-between">

0 commit comments

Comments
 (0)