Skip to content

Commit

Permalink
refactor: use getActiveKey to initialize the tab state
Browse files Browse the repository at this point in the history
on library authoring page.
  • Loading branch information
pomegranited committed Dec 30, 2024
1 parent 4fb6064 commit c59f109
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/library-authoring/LibraryAuthoringPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ const LibraryAuthoringPage = ({ returnToLibrarySelection }: LibraryAuthoringPage
const { insideCollections, insideComponents, navigateTo } = useLibraryRoutes();

// The activeKey determines the currently selected tab.
const [activeKey, setActiveKey] = useState<ContentType>(ContentType.home);
const getActiveKey = () => {
if (componentPickerMode) {
return ContentType.home;
}
if (insideCollections) {
return ContentType.collections;
}
Expand All @@ -157,16 +159,7 @@ const LibraryAuthoringPage = ({ returnToLibrarySelection }: LibraryAuthoringPage
}
return ContentType.home;
};

useEffect(() => {
const contentType = getActiveKey();

if (componentPickerMode) {
setActiveKey(ContentType.home);
} else {
setActiveKey(contentType);
}
}, []);
const [activeKey, setActiveKey] = useState<ContentType>(getActiveKey);

useEffect(() => {
if (!componentPickerMode) {
Expand Down

0 comments on commit c59f109

Please sign in to comment.