Skip to content

Commit aee1bdf

Browse files
committed
make sidebar nav maintain query string params
1 parent d4730f7 commit aee1bdf

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

apps/dojo/src/components/sidebar/sidebar.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React, { useState, useEffect } from "react";
44
import { EyeIcon as Eye, CodeIcon as Code, BookOpenTextIcon as Book } from "@phosphor-icons/react";
55
import { cn } from "@/lib/utils";
6-
import { useRouter, usePathname } from "next/navigation";
6+
import { useRouter, usePathname, useSearchParams } from "next/navigation";
77
import { DemoList } from "@/components/demo-list/demo-list";
88
import { ThemeToggle } from "@/components/ui/theme-toggle";
99
import { ChevronDown } from "lucide-react";
@@ -31,6 +31,7 @@ interface SidebarProps {
3131
export function Sidebar({ isMobile, onMobileClose }: SidebarProps) {
3232
const router = useRouter();
3333
const pathname = usePathname();
34+
const searchParams = useSearchParams();
3435
const { theme, setTheme } = useTheme();
3536
const isDarkTheme = theme === "dark"
3637
const { view, frameworkPickerHidden, viewPickerHidden, featurePickerHidden, setView} = useURLParams();
@@ -56,7 +57,10 @@ export function Sidebar({ isMobile, onMobileClose }: SidebarProps) {
5657
// Handle selecting a demo
5758
const handleDemoSelect = (demoId: string) => {
5859
if (currentIntegration) {
59-
router.push(`/${currentIntegration.id}/feature/${demoId}`);
60+
const queryString = searchParams.toString();
61+
const newPath = `/${currentIntegration.id}/feature/${demoId}`;
62+
const url = queryString ? `${newPath}?${queryString}` : newPath;
63+
router.push(url);
6064
// Close mobile sidebar when demo is selected
6165
if (isMobile && onMobileClose) {
6266
onMobileClose();
@@ -66,7 +70,10 @@ export function Sidebar({ isMobile, onMobileClose }: SidebarProps) {
6670

6771
// Handle integration selection
6872
const handleIntegrationSelect = (integrationId: string) => {
69-
router.push(`/${integrationId}`);
73+
const queryString = searchParams.toString();
74+
const newPath = `/${integrationId}`;
75+
const url = queryString ? `${newPath}?${queryString}` : newPath;
76+
router.push(url);
7077
};
7178

7279
const tabClass = `cursor-pointer flex-1 h-8 px-2 text-sm text-primary shadow-none bg-none border-none font-medium gap-1 rounded-lg data-[state=active]:bg-white data-[state=active]:text-primary data-[state=active]:shadow-none`

0 commit comments

Comments
 (0)