Fixes: No redirect after doc import

This commit is contained in:
Tom Moor
2019-01-26 17:28:08 +00:00
parent e7e94cdef2
commit b46db25553
3 changed files with 14 additions and 18 deletions

View File

@ -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<Props> {
@observable isImporting: boolean = false;
@observable redirectTo: ?string;
onDropAccepted = async (files = []) => {
this.isImporting = true;
@ -60,7 +62,7 @@ class DropToImport extends React.Component<Props> {
});
if (redirect) {
this.redirectTo = doc.url;
this.props.history.push(doc.url);
}
}
} finally {
@ -77,14 +79,13 @@ class DropToImport extends React.Component<Props> {
...rest
} = this.props;
if (this.redirectTo) return <Redirect to={this.redirectTo} push />;
if (this.props.disabled) return this.props.children;
return (
<Dropzone
accept="text/markdown, text/plain"
onDropAccepted={this.onDropAccepted}
style={{}}
style={EMPTY_OBJECT}
disableClick
disablePreview
multiple
@ -97,4 +98,4 @@ class DropToImport extends React.Component<Props> {
}
}
export default inject('documents')(DropToImport);
export default inject('documents')(withRouter(DropToImport));

View File

@ -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<Props> {
@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<Props> {
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<Props> {
};
render() {
if (this.redirectTo) return <Redirect to={this.redirectTo} push />;
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));

View File

@ -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);