fix: remove animation and retain expanded state

This commit is contained in:
Saumya Pandey committed 2022-02-17 00:28:53 +05:30
1 parent 99c39461e9
commit 9fb1da3d31
3 files changed
+20 -34

No files matched your search

@@ -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<boolean | null>(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({
/>
)}
</div>
<Transition
$expanded={expanded}
$maxHeight={
expanded ? (collection?.documentIds?.length ?? 1) * 80 + "px" : "0px"
}
>
{collectionDocuments.map((node, index) => (
{expanded &&
collectionDocuments.map((node, index) => (
<DocumentLink
key={node.id}
node={node}
@@ -306,7 +311,6 @@ function CollectionLink({
index={index}
/>
))}
</Transition>
<Modal
title={t("Move document")}
onRequestClose={handlePermissionClose}
@@ -21,7 +21,6 @@ import DropCursor from "./DropCursor";
import DropToImport from "./DropToImport";
import EditableTitle from "./EditableTitle";
import SidebarLink, { DragObject } from "./SidebarLink";
import Transition from "./Transition";
type Props = {
node: NavigationNode;
@@ -352,15 +351,9 @@ function DocumentLink(
<DropCursor isActiveDrop={isOverReorder} innerRef={dropToReorder} />
)}
</Relative>
<Transition
$expanded={expanded && !isDragging}
$maxHeight={
expanded && !isDragging
? (collection?.documentIds?.length ?? 1) * 80 + "px"
: "0px"
}
>
{nodeChildren.map((childNode, index) => (
{expanded &&
!isDragging &&
nodeChildren.map((childNode, index) => (
<ObservedDocumentLink
key={childNode.id}
collection={collection}
@@ -374,7 +367,6 @@ function DocumentLink(
parentId={node.id}
/>
))}
</Transition>
</>
);
}
@@ -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;