mirror of
https://github.com/outline/outline.git
synced 2026-11-22 22:02:35 +03:00
fix: move to client side
This commit is contained in:
1 parent
00f65ce29d
commit
a22e50cd3d
4 files changed
+58
-69
No files matched your search
@@ -17,7 +17,7 @@ import useStores from "~/hooks/useStores";
|
||||
import useToasts from "~/hooks/useToasts";
|
||||
import CollectionMenu from "~/menus/CollectionMenu";
|
||||
import CollectionSortMenu from "~/menus/CollectionSortMenu";
|
||||
import { NavigationNode, ToastOptions } from "~/types";
|
||||
import { ToastOptions } from "~/types";
|
||||
import DocumentLink from "./DocumentLink";
|
||||
import DropCursor from "./DropCursor";
|
||||
import DropToImport from "./DropToImport";
|
||||
@@ -34,28 +34,28 @@ type Props = {
|
||||
|
||||
type MoveType = {
|
||||
documents: DocumentsStore;
|
||||
documentId: string;
|
||||
collectionId: string;
|
||||
parentDocumentId?: string | null;
|
||||
index?: number | null;
|
||||
move: {
|
||||
collectionId: string;
|
||||
parentDocumentId?: string | null;
|
||||
index?: number | null;
|
||||
};
|
||||
showToast: (message: string, options?: ToastOptions) => string | undefined;
|
||||
t: TFunction<"translation", undefined>;
|
||||
item: DragObject;
|
||||
};
|
||||
|
||||
export const moveDocumentWithUndo = async ({
|
||||
documents,
|
||||
documentId,
|
||||
collectionId,
|
||||
parentDocumentId,
|
||||
index,
|
||||
showToast,
|
||||
t,
|
||||
move,
|
||||
item,
|
||||
}: MoveType) => {
|
||||
const undo = await documents.move(
|
||||
documentId,
|
||||
collectionId,
|
||||
parentDocumentId,
|
||||
index
|
||||
await documents.move(
|
||||
item.id,
|
||||
move.collectionId,
|
||||
move.parentDocumentId,
|
||||
move.index
|
||||
);
|
||||
|
||||
showToast(t("Document moved"), {
|
||||
@@ -64,10 +64,10 @@ export const moveDocumentWithUndo = async ({
|
||||
text: "undo",
|
||||
onClick: async () => {
|
||||
await documents.move(
|
||||
documentId,
|
||||
undo.collectionId,
|
||||
undo.parentDocumentId,
|
||||
undo.index
|
||||
item.id,
|
||||
item.collectionId,
|
||||
item.parentDocumentId,
|
||||
item.index
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -91,9 +91,7 @@ function CollectionLink({
|
||||
handlePermissionOpen,
|
||||
handlePermissionClose,
|
||||
] = useBoolean();
|
||||
const itemRef = React.useRef<
|
||||
NavigationNode & { depth: number; active: boolean; collectionId: string }
|
||||
>();
|
||||
const itemRef = React.useRef<DragObject | undefined>();
|
||||
const [isEditing, setIsEditing] = React.useState(false);
|
||||
|
||||
const handleTitleChange = React.useCallback(
|
||||
@@ -123,16 +121,16 @@ function CollectionLink({
|
||||
const [{ isOver, canDrop }, drop] = useDrop({
|
||||
accept: "document",
|
||||
drop: async (item: DragObject, monitor) => {
|
||||
const { id, collectionId } = item;
|
||||
const { collectionId, parentDocumentId } = item;
|
||||
|
||||
if (monitor.didDrop()) {
|
||||
return;
|
||||
}
|
||||
if (!collection) {
|
||||
if (!collection || !item) {
|
||||
return;
|
||||
}
|
||||
|
||||
const document = documents.get(id);
|
||||
if (collection.id === collectionId && !document?.parentDocumentId) {
|
||||
if (collection.id === collectionId && !parentDocumentId) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -148,10 +146,12 @@ function CollectionLink({
|
||||
} else {
|
||||
moveDocumentWithUndo({
|
||||
documents,
|
||||
documentId: id,
|
||||
collectionId: collection.id,
|
||||
showToast,
|
||||
t,
|
||||
item,
|
||||
move: {
|
||||
collectionId: collection.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -170,16 +170,19 @@ function CollectionLink({
|
||||
const [{ isOverReorder }, dropToReorder] = useDrop({
|
||||
accept: "document",
|
||||
drop: async (item: DragObject) => {
|
||||
if (!collection) {
|
||||
if (!collection || !item.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
moveDocumentWithUndo({
|
||||
documents,
|
||||
documentId: item.id,
|
||||
collectionId: collection.id,
|
||||
index: 0,
|
||||
showToast,
|
||||
t,
|
||||
move: {
|
||||
collectionId: collection.id,
|
||||
index: 0,
|
||||
},
|
||||
item,
|
||||
});
|
||||
},
|
||||
collect: (monitor) => ({
|
||||
|
||||
@@ -143,6 +143,7 @@ function DocumentLink(
|
||||
active: isActiveDocument,
|
||||
parentDocumentId: document?.parentDocumentId,
|
||||
collectionId: collection?.id || "",
|
||||
index,
|
||||
}),
|
||||
collect: (monitor) => ({
|
||||
isDragging: !!monitor.isDragging(),
|
||||
@@ -175,16 +176,20 @@ function DocumentLink(
|
||||
if (monitor.didDrop()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!collection) {
|
||||
return;
|
||||
}
|
||||
|
||||
moveDocumentWithUndo({
|
||||
documents,
|
||||
documentId: item.id,
|
||||
collectionId: collection.id,
|
||||
parentDocumentId: node.id,
|
||||
move: {
|
||||
collectionId: collection.id,
|
||||
parentDocumentId: node.id,
|
||||
},
|
||||
showToast,
|
||||
t,
|
||||
item,
|
||||
});
|
||||
},
|
||||
canDrop: (_item, monitor) =>
|
||||
@@ -235,27 +240,19 @@ function DocumentLink(
|
||||
return;
|
||||
}
|
||||
|
||||
if (expanded) {
|
||||
moveDocumentWithUndo({
|
||||
documents,
|
||||
documentId: item.id,
|
||||
collectionId: collection.id,
|
||||
parentDocumentId: node.id,
|
||||
showToast,
|
||||
t,
|
||||
index: 0,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const parentDocumentId = expanded ? node.id : parentId;
|
||||
const droppedDocumentIndex = expanded ? 0 : index + 1;
|
||||
|
||||
moveDocumentWithUndo({
|
||||
documents,
|
||||
documentId: item.id,
|
||||
collectionId: collection.id,
|
||||
parentDocumentId: parentId,
|
||||
showToast,
|
||||
t,
|
||||
index: index + 1,
|
||||
move: {
|
||||
collectionId: collection.id,
|
||||
parentDocumentId,
|
||||
index: droppedDocumentIndex,
|
||||
},
|
||||
item,
|
||||
});
|
||||
},
|
||||
collect: (monitor) => ({
|
||||
|
||||
@@ -12,6 +12,7 @@ export type DragObject = NavigationNode & {
|
||||
active: boolean;
|
||||
collectionId: string;
|
||||
parentDocumentId?: string;
|
||||
index: number;
|
||||
};
|
||||
|
||||
type Props = Omit<NavLinkProps, "to"> & {
|
||||
|
||||
@@ -7,26 +7,12 @@ import Button from "~/components/Button";
|
||||
import Flex from "~/components/Flex";
|
||||
import HelpText from "~/components/HelpText";
|
||||
import { moveDocumentWithUndo } from "~/components/Sidebar/components/CollectionLink";
|
||||
import { DragObject } from "~/components/Sidebar/components/SidebarLink";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import useToasts from "~/hooks/useToasts";
|
||||
import { NavigationNode } from "~/types";
|
||||
|
||||
type Props = {
|
||||
item:
|
||||
| {
|
||||
active: boolean | null | undefined;
|
||||
children: Array<NavigationNode>;
|
||||
collectionId: string;
|
||||
depth: number;
|
||||
id: string;
|
||||
title: string;
|
||||
url: string;
|
||||
}
|
||||
| {
|
||||
id: string;
|
||||
collectionId: string;
|
||||
title: string;
|
||||
};
|
||||
item: DragObject;
|
||||
collection: Collection;
|
||||
onCancel: () => void;
|
||||
onSubmit: () => void;
|
||||
@@ -52,10 +38,12 @@ function DocumentReparent({ collection, item, onSubmit, onCancel }: Props) {
|
||||
try {
|
||||
await moveDocumentWithUndo({
|
||||
documents,
|
||||
documentId: item.id,
|
||||
collectionId: collection.id,
|
||||
move: {
|
||||
collectionId: collection.id,
|
||||
},
|
||||
showToast,
|
||||
t,
|
||||
item,
|
||||
});
|
||||
onSubmit();
|
||||
} catch (err) {
|
||||
@@ -66,7 +54,7 @@ function DocumentReparent({ collection, item, onSubmit, onCancel }: Props) {
|
||||
setIsSaving(false);
|
||||
}
|
||||
},
|
||||
[documents, item.id, collection.id, showToast, t, onSubmit]
|
||||
[documents, collection.id, showToast, t, item, onSubmit]
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user