From ef8be0dd0bc2dd144e93c63a48332e7da3f4f376 Mon Sep 17 00:00:00 2001 From: Saumya Pandey Date: Wed, 11 Aug 2021 01:16:01 +0530 Subject: [PATCH] Refactor PathToDocument --- app/components/PathToDocument.js | 14 +++----------- app/scenes/DocumentMove.js | 10 +++++++++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/components/PathToDocument.js b/app/components/PathToDocument.js index f9995e79f9..9ea87aa1fd 100644 --- a/app/components/PathToDocument.js +++ b/app/components/PathToDocument.js @@ -13,7 +13,7 @@ type Props = { result: DocumentPath, document?: ?Document, collection: ?Collection, - onSuccess?: () => void, + onSuccess?: (DocumentPath) => Promise, style?: Object, ref?: (?React.ElementRef<"div">) => void, }; @@ -22,16 +22,8 @@ type Props = { class PathToDocument extends React.Component { 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() { diff --git a/app/scenes/DocumentMove.js b/app/scenes/DocumentMove.js index 94a1048a2e..48c5cdd169 100644 --- a/app/scenes/DocumentMove.js +++ b/app/scenes/DocumentMove.js @@ -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(); };