Skip to content

Commit dd4b9db

Browse files
committed
fix: sync dashboard activeTab with URL search params
Replaces plain component state for activeTab with useSearchParams from next/navigation, so the selected dashboard tab is reflected in the URL query string (e.g. ?tab=outgoing). This enables deep-linking, proper back-button navigation, and page-reload persistence of the selected tab. Closes #1234
1 parent 6db14d7 commit dd4b9db

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import { Suspense } from "react";
12
import { WalletEntry } from "@/components/wallet/wallet-entry";
23

34
export default function AppDashboardPage() {
4-
return <WalletEntry />;
5+
return (
6+
<Suspense>
7+
<WalletEntry />
8+
</Suspense>
9+
);
510
}

frontend/src/components/dashboard/dashboard-view.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import React from "react";
44
import Link from "next/link";
5+
import { useSearchParams, useRouter } from "next/navigation";
56
import toast from "react-hot-toast";
67

78
/**
@@ -513,9 +514,14 @@ const RecentActivityList = React.memo(function RecentActivityList({
513514

514515
// ─── Main Component ───────────────────────────────────────────────────────────
515516

517+
const VALID_TAB_IDS = new Set(SIDEBAR_ITEMS.map((item) => item.id));
518+
516519
export function DashboardView({ session, onDisconnect }: DashboardViewProps) {
517520
const queryClient = useQueryClient();
518-
const [activeTab, setActiveTab] = React.useState("overview");
521+
const router = useRouter();
522+
const searchParams = useSearchParams();
523+
const tabParam = searchParams.get("tab");
524+
const activeTab = VALID_TAB_IDS.has(tabParam ?? "") ? (tabParam as string) : "overview";
519525
const [showWizard, setShowWizard] = React.useState(false);
520526
const [modal, setModal] = React.useState<ModalState>(null);
521527

@@ -1398,7 +1404,11 @@ export function DashboardView({ session, onDisconnect }: DashboardViewProps) {
13981404
className="sidebar-item"
13991405
data-active={activeTab === item.id ? "true" : undefined}
14001406
aria-current={activeTab === item.id ? "page" : undefined}
1401-
onClick={() => setActiveTab(item.id)}
1407+
onClick={() => {
1408+
const params = new URLSearchParams(searchParams.toString());
1409+
params.set("tab", item.id);
1410+
router.replace(`?${params.toString()}`);
1411+
}}
14021412
>
14031413
{item.label}
14041414
</button>

0 commit comments

Comments
 (0)