From a31836e9b97d0ecc67dd96ba412b4c52d30c9bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Wed, 16 Oct 2024 11:16:03 -0300 Subject: [PATCH] fix: set activeKey with navigation --- src/library-authoring/LibraryAuthoringPage.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/library-authoring/LibraryAuthoringPage.tsx b/src/library-authoring/LibraryAuthoringPage.tsx index 538d6f7653..786c976196 100644 --- a/src/library-authoring/LibraryAuthoringPage.tsx +++ b/src/library-authoring/LibraryAuthoringPage.tsx @@ -152,15 +152,17 @@ const LibraryAuthoringPage = ({ returnToLibrarySelection }: LibraryAuthoringPage openInfoSidebar, } = useLibraryContext(); - const currentPath = location.pathname.split('/').pop(); - let initialActiveKey: string | undefined; - if (componentPickerMode || currentPath === libraryId || currentPath === '') { - initialActiveKey = TabList.home; - } else if (currentPath && currentPath in TabList) { - initialActiveKey = TabList[currentPath]; - } + const [activeKey, setActiveKey] = useState(''); + + useEffect(() => { + const currentPath = location.pathname.split('/').pop(); - const [activeKey, setActiveKey] = useState(initialActiveKey); + if (componentPickerMode || currentPath === libraryId || currentPath === '') { + setActiveKey(TabList.home); + } else if (currentPath && currentPath in TabList) { + setActiveKey(TabList[currentPath]); + } + }, [location.pathname]); useEffect(() => { if (!componentPickerMode) {