diff --git a/app/components/Sidebar/components/CollectionLink.tsx b/app/components/Sidebar/components/CollectionLink.tsx index 7b00faa47b..c0fe1b42c0 100644 --- a/app/components/Sidebar/components/CollectionLink.tsx +++ b/app/components/Sidebar/components/CollectionLink.tsx @@ -22,7 +22,6 @@ import DropCursor from "./DropCursor"; import DropToImport from "./DropToImport"; import EditableTitle from "./EditableTitle"; import SidebarLink, { DragObject } from "./SidebarLink"; -import Transition from "./Transition"; type Props = { collection: Collection; @@ -133,11 +132,11 @@ function CollectionLink({ // Drop to reorder collection const [ - { isCollectionDropping, isDraggingAnotherCollection }, + { isCollectionDropping, isDraggingAnotherCollection, isCollectionDropped }, dropToReorderCollection, ] = useDrop({ accept: "collection", - drop: async (item: DragObject) => { + drop: (item: DragObject) => { collections.move( item.id, fractionalIndex(collection.index, belowCollectionIndex) @@ -152,6 +151,7 @@ function CollectionLink({ collect: (monitor) => ({ isCollectionDropping: monitor.isOver(), isDraggingAnotherCollection: monitor.canDrop(), + isCollectionDropped: monitor.didDrop(), }), }); @@ -199,11 +199,21 @@ function CollectionLink({ const isDraggingAnyCollection = isDraggingAnotherCollection || isCollectionDragging; + const expandedStateBeforeDragging = React.useRef(null); + React.useEffect(() => { if (isDraggingAnyCollection) { + expandedStateBeforeDragging.current = + expandedStateBeforeDragging.current ?? expanded; setExpanded(false); + } else if ( + isCollectionDropped && + expandedStateBeforeDragging.current !== null + ) { + setExpanded(expandedStateBeforeDragging.current); + expandedStateBeforeDragging.current = null; } - }, [collection.name, isDraggingAnyCollection]); + }, [expanded, isCollectionDropped, isDraggingAnyCollection]); React.useEffect(() => { // If we're viewing a starred document through the starred menu then don't @@ -255,7 +265,7 @@ function CollectionLink({ /> } exact={false} - depth={0.6} + depth={0.5} menu={ !isEditing && ( <> @@ -287,13 +297,8 @@ function CollectionLink({ /> )} - - {collectionDocuments.map((node, index) => ( + {expanded && + collectionDocuments.map((node, index) => ( ))} - )} - - {nodeChildren.map((childNode, index) => ( + {expanded && + !isDragging && + nodeChildren.map((childNode, index) => ( ))} - ); } diff --git a/app/components/Sidebar/components/Transition.tsx b/app/components/Sidebar/components/Transition.tsx deleted file mode 100644 index c2cf27e3de..0000000000 --- a/app/components/Sidebar/components/Transition.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import styled from "styled-components"; - -const Transition = styled.div<{ $expanded: boolean; $maxHeight: string }>` - max-height: ${(props) => props.$maxHeight}; - transition: ${(props) => - props.$expanded ? "max-height 300ms ease-in" : "max-height 400ms ease-out"}; - overflow: hidden; -`; - -export default Transition;