issue-537

This commit is contained in:
Tom Moor
2018-01-29 22:31:49 -08:00
parent 7be5b5fa0d
commit ba72ecb0e3
5 changed files with 119 additions and 69 deletions

36
app/utils/importFile.js Normal file
View File

@ -0,0 +1,36 @@
// @flow
import Document from '../models/Document';
import DocumentsStore from '../stores/DocumentsStore';
type Options = {
file: File,
documents: DocumentsStore,
collectionId: string,
documentId?: string,
};
const importFile = async (
{ documents, file, documentId, collectionId }: Options,
callback: Document => *
) => {
const reader = new FileReader();
reader.onload = async ev => {
const text = ev.target.result;
let data = {
parentDocument: undefined,
collection: { id: collectionId },
text,
};
if (documentId) data.parentDocument = documentId;
let document = new Document(data);
document = await document.save();
documents.add(document);
callback(document);
};
reader.readAsText(file);
};
export default importFile;