mirror of
https://github.com/outline/outline.git
synced 2026-11-26 07:33:19 +03:00
Refactor PathToDocument
This commit is contained in:
1 parent
44f3ef869a
commit
ef8be0dd0b
2 files changed
+12
-12
No files matched your search
@@ -13,7 +13,7 @@ type Props = {
|
||||
result: DocumentPath,
|
||||
document?: ?Document,
|
||||
collection: ?Collection,
|
||||
onSuccess?: () => void,
|
||||
onSuccess?: (DocumentPath) => Promise<void>,
|
||||
style?: Object,
|
||||
ref?: (?React.ElementRef<"div">) => void,
|
||||
};
|
||||
@@ -22,16 +22,8 @@ type Props = {
|
||||
class PathToDocument extends React.Component<Props> {
|
||||
handleClick = async (ev: SyntheticEvent<>) => {
|
||||
ev.preventDefault();
|
||||
const { document, result, onSuccess } = this.props;
|
||||
if (!document) return;
|
||||
|
||||
if (result.type === "document") {
|
||||
await document.move(result.collectionId, result.id);
|
||||
} else {
|
||||
await document.move(result.collectionId, null);
|
||||
}
|
||||
|
||||
if (onSuccess) onSuccess();
|
||||
const { onSuccess, result } = this.props;
|
||||
if (onSuccess) await onSuccess(result);
|
||||
};
|
||||
|
||||
render() {
|
||||
|
||||
@@ -78,7 +78,15 @@ function DocumentMove({ document, onRequestClose }: Props) {
|
||||
return results;
|
||||
}, [document, collections, searchTerm, searchIndex]);
|
||||
|
||||
const handleSuccess = () => {
|
||||
const handleSuccess = async (result: DocumentPath) => {
|
||||
if (!document) return;
|
||||
|
||||
if (result.type === "document") {
|
||||
await document.move(result.collectionId, result.id);
|
||||
} else {
|
||||
await document.move(result.collectionId, null);
|
||||
}
|
||||
|
||||
showToast(t("Document moved"), { type: "info" });
|
||||
onRequestClose();
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user