* Big upgrades * WIP: Stash * Stash, 30 flow errors left * Downgrade mobx * WIP * When I understand the difference between class and instance methods * 💚 * Fixes: File import Model saving edge cases pinning and starring docs Collection editing Upgrade mobx devtools * Notification settings saving works * Disabled settings * Document mailer * Working notifications * Colletion created notification Ensure not notified for own actions * Tidy up * Document updated event only for document creation Add indexes Notification setting on user creation * Commentary * Fixed: Notification setting on signup * Fix document move / duplicate stale data Add BaseModel.refresh method * Fixes: Title in sidebar not updated after editing document * 💚 * Improve / restore error handling Better handle offline errors * 👕
102 lines
2.4 KiB
JavaScript
102 lines
2.4 KiB
JavaScript
// @flow
|
|
import * as React from 'react';
|
|
import { observable } from 'mobx';
|
|
import { observer, inject } from 'mobx-react';
|
|
import { createGlobalStyle } from 'styled-components';
|
|
import { omit } from 'lodash';
|
|
import invariant from 'invariant';
|
|
import importFile from 'utils/importFile';
|
|
import Dropzone from 'react-dropzone';
|
|
import DocumentsStore from 'stores/DocumentsStore';
|
|
import LoadingIndicator from 'components/LoadingIndicator';
|
|
|
|
type Props = {
|
|
children: React.Node,
|
|
collectionId: string,
|
|
documentId?: string,
|
|
activeClassName?: string,
|
|
rejectClassName?: string,
|
|
documents: DocumentsStore,
|
|
disabled: boolean,
|
|
history: Object,
|
|
};
|
|
|
|
const GlobalStyles = createGlobalStyle`
|
|
.activeDropZone {
|
|
background: ${props => props.theme.slateDark};
|
|
svg { fill: ${props => props.theme.white}; }
|
|
}
|
|
|
|
.activeDropZone a {
|
|
color: ${props => props.theme.white} !important;
|
|
}
|
|
`;
|
|
|
|
@observer
|
|
class DropToImport extends React.Component<Props> {
|
|
@observable isImporting: boolean = false;
|
|
|
|
onDropAccepted = async (files = []) => {
|
|
this.isImporting = true;
|
|
|
|
try {
|
|
let collectionId = this.props.collectionId;
|
|
const documentId = this.props.documentId;
|
|
const redirect = files.length === 1;
|
|
|
|
if (documentId && !collectionId) {
|
|
const document = await this.props.documents.fetch(documentId);
|
|
invariant(document, 'Document not available');
|
|
collectionId = document.collection.id;
|
|
}
|
|
|
|
for (const file of files) {
|
|
const doc = await importFile({
|
|
documents: this.props.documents,
|
|
file,
|
|
documentId,
|
|
collectionId,
|
|
});
|
|
|
|
if (redirect) {
|
|
this.props.history.push(doc.url);
|
|
}
|
|
}
|
|
} finally {
|
|
this.isImporting = false;
|
|
}
|
|
};
|
|
|
|
render() {
|
|
const props = omit(
|
|
this.props,
|
|
'history',
|
|
'documentId',
|
|
'collectionId',
|
|
'documents',
|
|
'disabled',
|
|
'menuOpen'
|
|
);
|
|
|
|
if (this.props.disabled) return this.props.children;
|
|
|
|
return (
|
|
<Dropzone
|
|
accept="text/markdown, text/plain"
|
|
onDropAccepted={this.onDropAccepted}
|
|
style={{}}
|
|
disableClick
|
|
disablePreview
|
|
multiple
|
|
{...props}
|
|
>
|
|
<GlobalStyles />
|
|
{this.isImporting && <LoadingIndicator />}
|
|
{this.props.children}
|
|
</Dropzone>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default inject('documents')(DropToImport);
|