refactor: documents.batchImport -> collections.import
This commit is contained in:
@@ -19,7 +19,7 @@ function ImportExport() {
|
||||
const { t } = useTranslation();
|
||||
const user = useCurrentUser();
|
||||
const fileRef = React.useRef();
|
||||
const { ui, collections, documents } = useStores();
|
||||
const { ui, collections } = useStores();
|
||||
const { showToast } = ui;
|
||||
const [isLoading, setLoading] = React.useState(false);
|
||||
const [isImporting, setImporting] = React.useState(false);
|
||||
@@ -34,7 +34,7 @@ function ImportExport() {
|
||||
setImporting(true);
|
||||
|
||||
try {
|
||||
const { documentCount, collectionCount } = await documents.batchImport(
|
||||
const { documentCount, collectionCount } = await collections.import(
|
||||
file
|
||||
);
|
||||
showToast(t("Import completed"));
|
||||
@@ -50,7 +50,7 @@ function ImportExport() {
|
||||
setImportDetails(undefined);
|
||||
}
|
||||
},
|
||||
[t, file, documents, showToast]
|
||||
[t, file, collections, showToast]
|
||||
);
|
||||
|
||||
const handleFilePicked = React.useCallback(async (ev) => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// @flow
|
||||
import invariant from "invariant";
|
||||
import { concat, filter, last } from "lodash";
|
||||
import { computed } from "mobx";
|
||||
import { action, computed } from "mobx";
|
||||
|
||||
import naturalSort from "shared/utils/naturalSort";
|
||||
import Collection from "models/Collection";
|
||||
@@ -88,6 +89,21 @@ export default class CollectionsStore extends BaseStore<Collection> {
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
import = async (file: File) => {
|
||||
const formData = new FormData();
|
||||
formData.append("type", "outline");
|
||||
formData.append("file", file);
|
||||
|
||||
const res = await client.post("/collections.import", formData);
|
||||
invariant(res && res.data, "Data should be available");
|
||||
|
||||
this.addPolicies(res.policies);
|
||||
res.data.collections.forEach(this.add);
|
||||
|
||||
return res.data;
|
||||
};
|
||||
|
||||
getPathForDocument(documentId: string): ?DocumentPath {
|
||||
return this.pathsToDocuments.find((path) => path.id === documentId);
|
||||
}
|
||||
|
||||
@@ -497,21 +497,6 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
return this.add(res.data);
|
||||
};
|
||||
|
||||
@action
|
||||
batchImport = async (file: File) => {
|
||||
const formData = new FormData();
|
||||
formData.append("type", "outline");
|
||||
formData.append("file", file);
|
||||
|
||||
const res = await client.post("/documents.batchImport", formData);
|
||||
invariant(res && res.data, "Data should be available");
|
||||
|
||||
this.addPolicies(res.policies);
|
||||
res.data.collections.forEach(this.rootStore.collections.add);
|
||||
|
||||
return res.data;
|
||||
};
|
||||
|
||||
@action
|
||||
import = async (
|
||||
file: File,
|
||||
|
||||
Reference in New Issue
Block a user