Skip to content

Commit

Permalink
refactor(ui): move code into clean sections
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis SMAIL committed Dec 6, 2024
1 parent b59eb6f commit 474169b
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions webapp/src/components/App/Studies/StudyTree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@ function StudyTree() {
const dispatch = useAppDispatch();
const [t] = useTranslation();

const updateTree = async (itemId: string, studyTreeNode: StudyTreeNode) => {
////////////////////////////////////////////////////////////////
// initialize
////////////////////////////////////////////////////////////////

// Initialize folders once we have the tree
// we use useUpdateEffectOnce because at first render initialStudiesTree isn't initialized
useUpdateEffectOnce(() => {
updateTree("root", initialStudiesTree);
}, [initialStudiesTree]);

////////////////////////////////////////////////////////////////
// utils
////////////////////////////////////////////////////////////////

async function updateTree(itemId: string, studyTreeNode: StudyTreeNode) {
let treeAfterWorkspacesUpdate = studiesTree;
let chidrenPaths = studyTreeNode.children.map(
(child) => `root${child.path}`,
Expand Down Expand Up @@ -68,13 +82,7 @@ function StudyTree() {
);
}
setStudiesTree(treeAfterChildrenUpdate);
};

// Initialize folders once we have the tree
// we use useUpdateEffectOnce because at first render initialStudiesTree isn't initialized
useUpdateEffectOnce(() => {
updateTree("root", initialStudiesTree);
}, [initialStudiesTree]);
}

////////////////////////////////////////////////////////////////
// Event Handlers
Expand Down

0 comments on commit 474169b

Please sign in to comment.