* Migrations
* WIP: Integration model, slack perms / hooks
* So so rough it pains me. Building this new model is revealing just how much needs to be refactored
* Working connect and post
* Cleanup UI, upating documents
* Show when slack command is connected
* stash
* 💚
* Add documents.update trigger
* Authorization, tidying
* Fixed integration policy
* pick integration presenter keys
41 lines
868 B
JavaScript
41 lines
868 B
JavaScript
// @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): Promise<Document> => {
|
|
return new Promise(resolve => {
|
|
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(true);
|
|
documents.add(document);
|
|
resolve(document);
|
|
};
|
|
reader.readAsText(file);
|
|
});
|
|
};
|
|
|
|
export default importFile;
|