refactor
This commit is contained in:
parent
7a6e14d12f
commit
02ee68e5a3
|
@ -2,6 +2,7 @@ import { Modal, Button } from 'react-bootstrap';
|
|||
import React from 'react';
|
||||
import ImportService from 'services/importService';
|
||||
import { getElectronFiles } from 'utils/upload';
|
||||
import constants from 'utils/strings/constants';
|
||||
|
||||
export default function FileTypeChoiceModal({
|
||||
setElectronFiles,
|
||||
|
@ -33,7 +34,7 @@ export default function FileTypeChoiceModal({
|
|||
centered>
|
||||
<Modal.Header closeButton onHide={hideFiletypeDialog}>
|
||||
<Modal.Title id="contained-modal-title-vcenter">
|
||||
Upload
|
||||
{constants.CHOOSE_UPLOAD_TYPE}
|
||||
</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body
|
||||
|
@ -44,10 +45,10 @@ export default function FileTypeChoiceModal({
|
|||
height: '12vh',
|
||||
}}>
|
||||
<Button variant="outline-success" onClick={uploadFiles}>
|
||||
Upload Files
|
||||
{constants.UPLOAD_FILES}
|
||||
</Button>
|
||||
<Button variant="outline-success" onClick={uploadDirs}>
|
||||
Upload Folders
|
||||
{constants.UPLOAD_DIRS}
|
||||
</Button>
|
||||
</Modal.Body>
|
||||
</Modal>
|
||||
|
|
|
@ -149,13 +149,23 @@ export default function Upload(props: Props) {
|
|||
|
||||
const uploadFailedFiles = async () => {
|
||||
try {
|
||||
uploadInit();
|
||||
const { files, collections } =
|
||||
const { files, collectionName, collectionIDs } =
|
||||
await ImportService.getToUploadFiles();
|
||||
await uploadFiles(
|
||||
files as FileWithCollection[],
|
||||
collections as Collection[]
|
||||
);
|
||||
|
||||
toUploadFiles = files;
|
||||
|
||||
if (collectionName) {
|
||||
uploadToSingleNewCollection(collectionName);
|
||||
} else {
|
||||
uploadInit();
|
||||
const filesWithCollectionToUpload: FileWithCollection[] =
|
||||
toUploadFiles.map((file, index) => ({
|
||||
file,
|
||||
localID: index,
|
||||
collectionID: collectionIDs[index],
|
||||
}));
|
||||
await uploadFiles(filesWithCollectionToUpload);
|
||||
}
|
||||
} catch (e) {
|
||||
logError(e, 'Failed to upload previously failed files');
|
||||
} finally {
|
||||
|
@ -218,7 +228,6 @@ export default function Upload(props: Props) {
|
|||
|
||||
const uploadFilesToExistingCollection = async (collection) => {
|
||||
try {
|
||||
console.log('uploadFilesToExistingCollection');
|
||||
uploadInit();
|
||||
const filesWithCollectionToUpload: FileWithCollection[] =
|
||||
toUploadFiles.map((file, index) => ({
|
||||
|
@ -237,7 +246,6 @@ export default function Upload(props: Props) {
|
|||
collectionName?: string
|
||||
) => {
|
||||
try {
|
||||
console.log('uploadFilesToNewCollections');
|
||||
uploadInit();
|
||||
|
||||
const filesWithCollectionToUpload: FileWithCollection[] = [];
|
||||
|
@ -290,7 +298,6 @@ export default function Upload(props: Props) {
|
|||
filesWithCollectionToUpload: FileWithCollection[],
|
||||
collections?: Collection[]
|
||||
) => {
|
||||
console.log(collections);
|
||||
try {
|
||||
props.setUploadInProgress(true);
|
||||
props.closeCollectionSelector();
|
||||
|
@ -341,7 +348,6 @@ export default function Upload(props: Props) {
|
|||
};
|
||||
|
||||
const uploadToSingleNewCollection = (collectionName: string) => {
|
||||
console.log('uploadToSingleNewCollection');
|
||||
if (collectionName) {
|
||||
uploadFilesToNewCollections(
|
||||
UPLOAD_STRATEGY.SINGLE_COLLECTION,
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
import { Collection } from 'types/collection';
|
||||
import { ElectronFile, FileWithCollection } from 'types/upload';
|
||||
import { runningInBrowser } from 'utils/common';
|
||||
|
||||
interface FilesAndCollections {
|
||||
files: FileWithCollection[];
|
||||
collections: Collection[];
|
||||
}
|
||||
import { getElectronFiles } from 'utils/upload';
|
||||
|
||||
class ImportService {
|
||||
ElectronAPIs: any;
|
||||
|
@ -16,28 +12,9 @@ class ImportService {
|
|||
this.allElectronAPIsExist = !!this.ElectronAPIs?.exists;
|
||||
}
|
||||
|
||||
async setToUploadFiles(
|
||||
filesWithCollectionToUpload: FileWithCollection[],
|
||||
collections?: Collection[]
|
||||
) {
|
||||
if (this.allElectronAPIsExist) {
|
||||
this.ElectronAPIs.setToUploadFiles(
|
||||
filesWithCollectionToUpload,
|
||||
collections,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async setDoneUploadingFiles() {
|
||||
if (this.allElectronAPIsExist) {
|
||||
this.ElectronAPIs.setToUploadFiles([], [], true);
|
||||
}
|
||||
}
|
||||
|
||||
async getToUploadFiles(): Promise<FilesAndCollections> {
|
||||
if (this.allElectronAPIsExist) {
|
||||
return this.ElectronAPIs.getToUploadFiles();
|
||||
this.ElectronAPIs.setToUploadFiles(null, null, null, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,5 +41,40 @@ class ImportService {
|
|||
return this.ElectronAPIs.showUploadDirsDialog();
|
||||
}
|
||||
}
|
||||
|
||||
async getToUploadFiles() {
|
||||
if (this.allElectronAPIsExist) {
|
||||
const { filesPaths, collectionName, collectionIDs } =
|
||||
this.ElectronAPIs.getToUploadFiles();
|
||||
const files = await getElectronFiles(filesPaths);
|
||||
return {
|
||||
files,
|
||||
collectionName,
|
||||
collectionIDs,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async setToUploadFiles(
|
||||
files: FileWithCollection[],
|
||||
collections?: Collection[]
|
||||
) {
|
||||
if (this.allElectronAPIsExist) {
|
||||
let collectionName;
|
||||
if (collections?.length > 0) {
|
||||
collectionName = collections[0].name;
|
||||
}
|
||||
const filePaths = files.map(
|
||||
(file) => (file.file as ElectronFile).path
|
||||
);
|
||||
const collectionIDs = files.map((file) => file.collectionID);
|
||||
this.ElectronAPIs.setToUploadFiles(
|
||||
filePaths,
|
||||
collectionName,
|
||||
collectionIDs,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
export default new ImportService();
|
||||
|
|
|
@ -675,6 +675,9 @@ const englishConstants = {
|
|||
LIVE_PHOTO: 'this is a live photo',
|
||||
LIVE: 'LIVE',
|
||||
DOWNLOAD_UPLOAD_LOGS: 'debug logs',
|
||||
CHOOSE_UPLOAD_TYPE: 'Choose Upload Type',
|
||||
UPLOAD_FILES: 'Upload Files',
|
||||
UPLOAD_DIRS: 'Upload Folders',
|
||||
};
|
||||
|
||||
export default englishConstants;
|
||||
|
|
Loading…
Reference in a new issue