Restructure selection
This commit is contained in:
parent
881a963fde
commit
a5f9fdd10d
2 changed files with 29 additions and 30 deletions
|
@ -18,7 +18,10 @@ import { t } from "i18next";
|
|||
import isElectron from "is-electron";
|
||||
import { AppContext } from "pages/_app";
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import exportService, { ExportStage } from "services/export";
|
||||
import exportService, {
|
||||
ExportStage,
|
||||
selectAndPrepareExportDirectory,
|
||||
} from "services/export";
|
||||
import { ExportProgress, ExportSettings } from "types/export";
|
||||
import { EnteFile } from "types/file";
|
||||
import { getExportDirectoryDoesNotExistMessage } from "utils/ui";
|
||||
|
@ -117,17 +120,13 @@ export default function ExportModal(props: Props) {
|
|||
// =============
|
||||
|
||||
const handleChangeExportDirectoryClick = async () => {
|
||||
try {
|
||||
const newFolder = await exportService.changeExportDirectory();
|
||||
log.info(`Export folder changed to ${newFolder}`);
|
||||
exportService.updateExportSettings({ folder: newFolder });
|
||||
setExportFolder(newFolder);
|
||||
void syncExportRecord(newFolder);
|
||||
} catch (e) {
|
||||
if (e.message !== CustomError.SELECT_FOLDER_ABORTED) {
|
||||
log.error("handleChangeExportDirectoryClick failed", e);
|
||||
}
|
||||
}
|
||||
const newFolder = await selectAndPrepareExportDirectory();
|
||||
if (!newFolder) return;
|
||||
|
||||
log.info(`Export folder changed to ${newFolder}`);
|
||||
exportService.updateExportSettings({ folder: newFolder });
|
||||
setExportFolder(newFolder);
|
||||
await syncExportRecord(newFolder);
|
||||
};
|
||||
|
||||
const toggleContinuousExport = async () => {
|
||||
|
|
|
@ -165,24 +165,6 @@ class ExportService {
|
|||
this.uiUpdater.setLastExportTime(exportTime);
|
||||
}
|
||||
|
||||
async changeExportDirectory() {
|
||||
const electron = ensureElectron();
|
||||
try {
|
||||
const newRootDir = await electron.selectDirectory();
|
||||
if (!newRootDir) {
|
||||
throw Error(CustomError.SELECT_FOLDER_ABORTED);
|
||||
}
|
||||
const newExportDir = `${newRootDir}/${exportDirectoryName}`;
|
||||
await electron.fs.mkdirIfNeeded(newExportDir);
|
||||
return newExportDir;
|
||||
} catch (e) {
|
||||
if (e.message !== CustomError.SELECT_FOLDER_ABORTED) {
|
||||
log.error("changeExportDirectory failed", e);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
enableContinuousExport() {
|
||||
try {
|
||||
if (this.continuousExportEventHandler) {
|
||||
|
@ -1158,6 +1140,24 @@ export const resumeExportsIfNeeded = async () => {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Prompt the user to select a directory and create an export directory in it.
|
||||
*
|
||||
* If the user cancels the selection, return undefined.
|
||||
*/
|
||||
export const selectAndPrepareExportDirectory = async (): Promise<
|
||||
string | undefined
|
||||
> => {
|
||||
const electron = ensureElectron();
|
||||
|
||||
const rootDir = await electron.selectDirectory();
|
||||
if (!rootDir) return undefined;
|
||||
|
||||
const exportDir = `${rootDir}/${exportDirectoryName}`;
|
||||
await electron.fs.mkdirIfNeeded(exportDir);
|
||||
return exportDir;
|
||||
};
|
||||
|
||||
export const getExportRecordFileUID = (file: EnteFile) =>
|
||||
`${file.id}_${file.collectionID}_${file.updationTime}`;
|
||||
|
||||
|
|
Loading…
Reference in a new issue