fix: Clickable area for docs in sidebar is obstructed (#2809)

closes #2808
This commit is contained in:
Tom Moor
2021-12-03 06:44:06 -08:00
committed by GitHub
parent d8d3e2bef2
commit 82bc6ef45b
3 changed files with 29 additions and 33 deletions

View File

@@ -27,8 +27,6 @@ type Props = {
activeDocument: Document | null | undefined; activeDocument: Document | null | undefined;
prefetchDocument: (id: string) => Promise<any>; prefetchDocument: (id: string) => Promise<any>;
belowCollection: Collection | void; belowCollection: Collection | void;
isDraggingAnyCollection: boolean;
onChangeDragging: (dragging: boolean) => void;
}; };
function CollectionLink({ function CollectionLink({
@@ -37,8 +35,6 @@ function CollectionLink({
prefetchDocument, prefetchDocument,
canUpdate, canUpdate,
belowCollection, belowCollection,
isDraggingAnyCollection,
onChangeDragging,
}: Props) { }: Props) {
const history = useHistory(); const history = useHistory();
const { t } = useTranslation(); const { t } = useTranslation();
@@ -68,24 +64,11 @@ function CollectionLink({
collection.id === ui.activeCollectionId collection.id === ui.activeCollectionId
); );
React.useEffect(() => {
// If we're viewing a starred document through the starred menu then don't
// touch the expanded / collapsed state of the collections
if (search === "?starred") {
return;
}
if (isDraggingAnyCollection) {
setExpanded(false);
} else {
setExpanded(collection.id === ui.activeCollectionId);
}
}, [isDraggingAnyCollection, collection.id, ui.activeCollectionId, search]);
const manualSort = collection.sort.field === "index"; const manualSort = collection.sort.field === "index";
const can = policies.abilities(collection.id); const can = policies.abilities(collection.id);
const belowCollectionIndex = belowCollection ? belowCollection.index : null; const belowCollectionIndex = belowCollection ? belowCollection.index : null;
// Drop to re-parent // Drop to re-parent document
const [{ isOver, canDrop }, drop] = useDrop({ const [{ isOver, canDrop }, drop] = useDrop({
accept: "document", accept: "document",
drop: (item: DragObject, monitor) => { drop: (item: DragObject, monitor) => {
@@ -117,7 +100,7 @@ function CollectionLink({
}), }),
}); });
// Drop to reorder // Drop to reorder document
const [{ isOverReorder }, dropToReorder] = useDrop({ const [{ isOverReorder }, dropToReorder] = useDrop({
accept: "document", accept: "document",
drop: async (item: DragObject) => { drop: async (item: DragObject) => {
@@ -129,8 +112,11 @@ function CollectionLink({
}), }),
}); });
// Drop to reorder Collection // Drop to reorder collection
const [{ isCollectionDropping }, dropToReorderCollection] = useDrop({ const [
{ isCollectionDropping, isDraggingAnotherCollection },
dropToReorderCollection,
] = useDrop({
accept: "collection", accept: "collection",
drop: async (item: DragObject) => { drop: async (item: DragObject) => {
collections.move( collections.move(
@@ -146,14 +132,14 @@ function CollectionLink({
}, },
collect: (monitor) => ({ collect: (monitor) => ({
isCollectionDropping: monitor.isOver(), isCollectionDropping: monitor.isOver(),
isDraggingAnotherCollection: monitor.canDrop(),
}), }),
}); });
// Drag to reorder Collection // Drag to reorder collection
const [{ isCollectionDragging }, dragToReorderCollection] = useDrag({ const [{ isCollectionDragging }, dragToReorderCollection] = useDrag({
type: "collection", type: "collection",
item: () => { item: () => {
onChangeDragging(true);
return { return {
id: collection.id, id: collection.id,
}; };
@@ -164,11 +150,25 @@ function CollectionLink({
canDrag: () => { canDrag: () => {
return can.move; return can.move;
}, },
end: () => {
onChangeDragging(false);
},
}); });
const isDraggingAnyCollection =
isDraggingAnotherCollection || isCollectionDragging;
React.useEffect(() => {
// If we're viewing a starred document through the starred menu then don't
// touch the expanded / collapsed state of the collections
if (search === "?starred") {
return;
}
if (isDraggingAnyCollection) {
setExpanded(false);
} else {
setExpanded(collection.id === ui.activeCollectionId);
}
}, [isDraggingAnyCollection, collection.id, ui.activeCollectionId, search]);
return ( return (
<> <>
<div <div

View File

@@ -26,9 +26,6 @@ function Collections() {
const isPreloaded = !!collections.orderedData.length; const isPreloaded = !!collections.orderedData.length;
const { t } = useTranslation(); const { t } = useTranslation();
const orderedCollections = collections.orderedData; const orderedCollections = collections.orderedData;
const [isDraggingAnyCollection, setIsDraggingAnyCollection] = React.useState(
false
);
React.useEffect(() => { React.useEffect(() => {
async function load() { async function load() {
@@ -85,8 +82,6 @@ function Collections() {
activeDocument={documents.active} activeDocument={documents.active}
prefetchDocument={documents.prefetchDocument} prefetchDocument={documents.prefetchDocument}
canUpdate={policies.abilities(collection.id).update} canUpdate={policies.abilities(collection.id).update}
isDraggingAnyCollection={isDraggingAnyCollection}
onChangeDragging={setIsDraggingAnyCollection}
belowCollection={orderedCollections[index + 1]} belowCollection={orderedCollections[index + 1]}
/> />
))} ))}

View File

@@ -197,7 +197,7 @@ function DocumentLink(
}); });
// Drop to reorder // Drop to reorder
const [{ isOverReorder }, dropToReorder] = useDrop({ const [{ isOverReorder, isDraggingAnyDocument }, dropToReorder] = useDrop({
accept: "document", accept: "document",
drop: (item: DragObject) => { drop: (item: DragObject) => {
if (!collection) return; if (!collection) return;
@@ -212,6 +212,7 @@ function DocumentLink(
}, },
collect: (monitor) => ({ collect: (monitor) => ({
isOverReorder: !!monitor.isOver(), isOverReorder: !!monitor.isOver(),
isDraggingAnyDocument: !!monitor.canDrop(),
}), }),
}); });
@@ -274,7 +275,7 @@ function DocumentLink(
</DropToImport> </DropToImport>
</div> </div>
</Draggable> </Draggable>
{manualSort && ( {manualSort && isDraggingAnyDocument && (
<DropCursor isActiveDrop={isOverReorder} innerRef={dropToReorder} /> <DropCursor isActiveDrop={isOverReorder} innerRef={dropToReorder} />
)} )}
</Relative> </Relative>