From b46db2555320202970092c574a1339f8c94b40ae Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 26 Jan 2019 17:28:08 +0000 Subject: [PATCH] Fixes: No redirect after doc import --- app/components/DropToImport.js | 13 +++++++------ app/menus/CollectionMenu.js | 15 +++++---------- app/utils/importFile.js | 4 ++-- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/components/DropToImport.js b/app/components/DropToImport.js index 3be91370..e43eb1db 100644 --- a/app/components/DropToImport.js +++ b/app/components/DropToImport.js @@ -2,7 +2,7 @@ import * as React from 'react'; import { observable } from 'mobx'; import { observer, inject } from 'mobx-react'; -import { Redirect } from 'react-router-dom'; +import { withRouter } from 'react-router-dom'; import { createGlobalStyle } from 'styled-components'; import invariant from 'invariant'; import importFile from 'utils/importFile'; @@ -10,6 +10,8 @@ import Dropzone from 'react-dropzone'; import DocumentsStore from 'stores/DocumentsStore'; import LoadingIndicator from 'components/LoadingIndicator'; +const EMPTY_OBJECT = {}; + type Props = { children: React.Node, collectionId: string, @@ -18,6 +20,7 @@ type Props = { rejectClassName?: string, documents: DocumentsStore, disabled: boolean, + history: Object, }; export const GlobalStyles = createGlobalStyle` @@ -35,7 +38,6 @@ export const GlobalStyles = createGlobalStyle` @observer class DropToImport extends React.Component { @observable isImporting: boolean = false; - @observable redirectTo: ?string; onDropAccepted = async (files = []) => { this.isImporting = true; @@ -60,7 +62,7 @@ class DropToImport extends React.Component { }); if (redirect) { - this.redirectTo = doc.url; + this.props.history.push(doc.url); } } } finally { @@ -77,14 +79,13 @@ class DropToImport extends React.Component { ...rest } = this.props; - if (this.redirectTo) return ; if (this.props.disabled) return this.props.children; return ( { } } -export default inject('documents')(DropToImport); +export default inject('documents')(withRouter(DropToImport)); diff --git a/app/menus/CollectionMenu.js b/app/menus/CollectionMenu.js index c586b343..50fb6db6 100644 --- a/app/menus/CollectionMenu.js +++ b/app/menus/CollectionMenu.js @@ -2,7 +2,7 @@ import * as React from 'react'; import { observable } from 'mobx'; import { inject, observer } from 'mobx-react'; -import { Redirect } from 'react-router-dom'; +import { withRouter } from 'react-router-dom'; import styled from 'styled-components'; import { MoreIcon } from 'outline-icons'; import Modal from 'components/Modal'; @@ -22,6 +22,7 @@ type Props = { ui: UiStore, documents: DocumentsStore, collection: Collection, + history: Object, }; @observer @@ -30,14 +31,10 @@ class CollectionMenu extends React.Component { @observable permissionsModalOpen: boolean = false; @observable redirectTo: ?string; - componentDidUpdate() { - this.redirectTo = undefined; - } - onNewDocument = (ev: SyntheticEvent<*>) => { ev.preventDefault(); const { collection } = this.props; - this.redirectTo = `${collection.url}/new`; + this.props.history.push(`${collection.url}/new`); }; onImportDocument = (ev: SyntheticEvent<*>) => { @@ -56,7 +53,7 @@ class CollectionMenu extends React.Component { documents: this.props.documents, collectionId: this.props.collection.id, }); - this.redirectTo = document.url; + this.props.history.push(document.url); } catch (err) { this.props.ui.showToast(err.message); } @@ -90,8 +87,6 @@ class CollectionMenu extends React.Component { }; render() { - if (this.redirectTo) return ; - const { collection, label, onOpen, onClose } = this.props; return ( @@ -149,4 +144,4 @@ const HiddenInput = styled.input` visibility: hidden; `; -export default inject('ui', 'documents')(CollectionMenu); +export default inject('ui', 'documents')(withRouter(CollectionMenu)); diff --git a/app/utils/importFile.js b/app/utils/importFile.js index ebd98151..88052a8a 100644 --- a/app/utils/importFile.js +++ b/app/utils/importFile.js @@ -27,9 +27,9 @@ const importFile = async ({ if (documentId) data.parentDocument = documentId; - const document = new Document(data, documents); + let document = new Document(data, documents); try { - await document.save({ publish: true }); + document = await document.save({ publish: true }); resolve(document); } catch (err) { reject(err);