minor fix
This commit is contained in:
parent
9c51a65f31
commit
51cf8172ff
|
@ -1,4 +1,4 @@
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useMemo, useState } from "react";
|
||||||
import Tree, {
|
import Tree, {
|
||||||
mutateTree,
|
mutateTree,
|
||||||
moveItemOnTree,
|
moveItemOnTree,
|
||||||
|
@ -20,33 +20,35 @@ interface ExtendedTreeItem extends TreeItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
const CollectionListing = () => {
|
const CollectionListing = () => {
|
||||||
const [tree, setTree] = useState<TreeData>();
|
|
||||||
|
|
||||||
const { collections } = useCollectionStore();
|
const { collections } = useCollectionStore();
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const currentPath = router.asPath;
|
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(() => {
|
useEffect(() => {
|
||||||
const initialTree = buildTreeFromCollections(collections, router);
|
setTree(initialTree);
|
||||||
collections[0] && setTree(initialTree);
|
}, [initialTree]);
|
||||||
}, [collections]);
|
|
||||||
|
|
||||||
const onExpand = (itemId: ItemId) => {
|
const onExpand = (itemId: ItemId) => {
|
||||||
if (tree) {
|
|
||||||
setTree((currentTree) =>
|
setTree((currentTree) =>
|
||||||
mutateTree(currentTree!, itemId, { isExpanded: true })
|
mutateTree(currentTree!, itemId, { isExpanded: true })
|
||||||
);
|
);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onCollapse = (itemId: ItemId) => {
|
const onCollapse = (itemId: ItemId) => {
|
||||||
if (tree) {
|
|
||||||
setTree((currentTree) =>
|
setTree((currentTree) =>
|
||||||
mutateTree(currentTree as TreeData, itemId, { isExpanded: false })
|
mutateTree(currentTree as TreeData, itemId, { isExpanded: false })
|
||||||
);
|
);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onDragEnd = (
|
const onDragEnd = (
|
||||||
|
|
|
@ -98,7 +98,7 @@ export default function Sidebar({ className }: { className?: string }) {
|
||||||
leaveTo="transform opacity-0 -translate-y-3"
|
leaveTo="transform opacity-0 -translate-y-3"
|
||||||
>
|
>
|
||||||
<Disclosure.Panel>
|
<Disclosure.Panel>
|
||||||
<CollectionListing links={true} />
|
<CollectionListing />
|
||||||
</Disclosure.Panel>
|
</Disclosure.Panel>
|
||||||
</Transition>
|
</Transition>
|
||||||
</Disclosure>
|
</Disclosure>
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
declare module "@atlaskit/navigation";
|
|
Ŝarĝante…
Reference in New Issue