From 8f668d2c8ad412e23d823e83b3dd21b2812fe19d Mon Sep 17 00:00:00 2001 From: Haileyesus Date: Wed, 8 Apr 2026 16:35:29 +0300 Subject: [PATCH] fix: show correct active tab --- .../refactored/shared/layout/MainHeading.tsx | 15 +++++++++++++-- .../refactored/shared/layout/MobileNav.tsx | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/components/refactored/shared/layout/MainHeading.tsx b/src/components/refactored/shared/layout/MainHeading.tsx index 2cdce9c6..f314e27d 100644 --- a/src/components/refactored/shared/layout/MainHeading.tsx +++ b/src/components/refactored/shared/layout/MainHeading.tsx @@ -25,6 +25,17 @@ const decodeValue = (value?: string): string => { } }; +const resolveTabFromPathname = (pathname: string): string => { + const normalizedPath = pathname.replace(/\/+$/, ''); + const segments = normalizedPath.split('/').filter(Boolean); + + if (segments.length >= 3 && (segments[0] === 'workspaces' || segments[0] === 'sessions')) { + return decodeValue(segments[2]); + } + + return ''; +}; + const getTabTitle = (tab: AppTab, pluginDisplayName: string | undefined, t: (key: string) => string) => { if (tab.startsWith('plugin:') && pluginDisplayName) { return pluginDisplayName; @@ -69,13 +80,13 @@ export function MainHeading() { return decodeValue(params.get('name') ?? undefined); }, [location.search]); const activeTab = useMemo(() => { - const routeTab = decodeValue(tab); + const routeTab = decodeValue(tab) || resolveTabFromPathname(location.pathname); if (routeTab === 'plugins' && pluginName) { return `plugin:${pluginName}` as AppTab; } return (routeTab || 'chat') as AppTab; - }, [pluginName, tab]); + }, [location.pathname, pluginName, tab]); const pluginDisplayName = useMemo( () => diff --git a/src/components/refactored/shared/layout/MobileNav.tsx b/src/components/refactored/shared/layout/MobileNav.tsx index 1e34a99d..7a435d5c 100644 --- a/src/components/refactored/shared/layout/MobileNav.tsx +++ b/src/components/refactored/shared/layout/MobileNav.tsx @@ -52,6 +52,17 @@ const decodeValue = (value?: string): string => { } }; +const resolveTabFromPathname = (pathname: string): string => { + const normalizedPath = pathname.replace(/\/+$/, ''); + const segments = normalizedPath.split('/').filter(Boolean); + + if (segments.length >= 3 && (segments[0] === 'workspaces' || segments[0] === 'sessions')) { + return decodeValue(segments[2]); + } + + return ''; +}; + export function MobileNav() { const navigate = useNavigate(); const { t } = useTranslation(['common', 'settings']); @@ -72,13 +83,13 @@ export function MobileNav() { return decodeValue(params.get('name') ?? undefined); }, [location.search]); const activeTab = useMemo(() => { - const routeTab = decodeValue(tab); + const routeTab = decodeValue(tab) || resolveTabFromPathname(location.pathname); if (routeTab === 'plugins' && pluginName) { return `plugin:${pluginName}` as AppTab; } return (routeTab || 'chat') as AppTab; - }, [pluginName, tab]); + }, [location.pathname, pluginName, tab]); const isPluginActive = activeTab.startsWith('plugin:'); useEffect(() => {