From 51cf8172ffe13704fe15e85640963265ada408c1 Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Sat, 2 Mar 2024 09:07:33 -0500 Subject: [PATCH] minor fix --- components/CollectionListing.tsx | 34 +++++++++++++++++--------------- components/Sidebar.tsx | 2 +- types/nav.ts | 1 - 3 files changed, 19 insertions(+), 18 deletions(-) delete mode 100644 types/nav.ts diff --git a/components/CollectionListing.tsx b/components/CollectionListing.tsx index a428a10..716c150 100644 --- a/components/CollectionListing.tsx +++ b/components/CollectionListing.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect, useMemo, useState } from "react"; import Tree, { mutateTree, moveItemOnTree, @@ -20,33 +20,35 @@ interface ExtendedTreeItem extends TreeItem { } const CollectionListing = () => { - const [tree, setTree] = useState(); - const { collections } = useCollectionStore(); const router = useRouter(); const currentPath = router.asPath; + const initialTree = useMemo(() => { + if (collections.length > 0) { + return buildTreeFromCollections(collections, router); + } + return undefined; + }, [collections, router]); + + const [tree, setTree] = useState(initialTree); + useEffect(() => { - const initialTree = buildTreeFromCollections(collections, router); - collections[0] && setTree(initialTree); - }, [collections]); + setTree(initialTree); + }, [initialTree]); const onExpand = (itemId: ItemId) => { - if (tree) { - setTree((currentTree) => - mutateTree(currentTree!, itemId, { isExpanded: true }) - ); - } + setTree((currentTree) => + mutateTree(currentTree!, itemId, { isExpanded: true }) + ); }; const onCollapse = (itemId: ItemId) => { - if (tree) { - setTree((currentTree) => - mutateTree(currentTree as TreeData, itemId, { isExpanded: false }) - ); - } + setTree((currentTree) => + mutateTree(currentTree as TreeData, itemId, { isExpanded: false }) + ); }; const onDragEnd = ( diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx index d77dbac..b5fd88a 100644 --- a/components/Sidebar.tsx +++ b/components/Sidebar.tsx @@ -98,7 +98,7 @@ export default function Sidebar({ className }: { className?: string }) { leaveTo="transform opacity-0 -translate-y-3" > - + diff --git a/types/nav.ts b/types/nav.ts deleted file mode 100644 index 5fa8704..0000000 --- a/types/nav.ts +++ /dev/null @@ -1 +0,0 @@ -declare module "@atlaskit/navigation";