Improve trash dialog

Thanks to @Rubens10010
closes #618
fixes #698
pull/716/head
Mikael Finstad 5 years ago
parent a3a0d1ae34
commit 02c2d86a45
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -124,11 +124,13 @@ const App = memo(() => {
const [zoomWindowStartTime, setZoomWindowStartTime] = useState(0);
const [disabledSegmentIds, setDisabledSegmentIds] = useState({});
// State per application launch
const [keyframesEnabled, setKeyframesEnabled] = useState(true);
const [waveformEnabled, setWaveformEnabled] = useState(false);
const [thumbnailsEnabled, setThumbnailsEnabled] = useState(false);
const [showSideBar, setShowSideBar] = useState(true);
const [hideCanvasPreview, setHideCanvasPreview] = useState(false);
const [cleanupChoices, setCleanupChoices] = useState({});
// Segment related state
const [currentSegIndex, setCurrentSegIndex] = useState(0);
@ -866,13 +868,16 @@ const App = memo(() => {
if (!closeFile()) return;
const trashResponse = await cleanupFilesDialog();
console.log('trashResponse', trashResponse);
if (!trashResponse) return;
let trashResponse = cleanupChoices;
if (!cleanupChoices.dontShowAgain) {
trashResponse = await cleanupFilesDialog(cleanupChoices);
console.log('trashResponse', trashResponse);
if (!trashResponse) return; // Cancelled
setCleanupChoices(trashResponse); // Store for next time
}
const deleteTmpFiles = ['all', 'projectAndTmpFiles', 'tmpFiles'].includes(trashResponse);
const deleteProjectFile = ['all', 'projectAndTmpFiles'].includes(trashResponse);
const deleteOriginal = ['all'].includes(trashResponse);
const { tmpFiles: deleteTmpFiles, projectFile: deleteProjectFile, sourceFile: deleteOriginal } = trashResponse;
if (!deleteTmpFiles && !deleteProjectFile && !deleteOriginal) return;
try {
setWorking(i18n.t('Cleaning up'));

@ -1,4 +1,5 @@
import React from 'react';
import React, { useState } from 'react';
import { Checkbox } from 'evergreen-ui';
import Swal from 'sweetalert2';
import i18n from 'i18next';
import { Trans } from 'react-i18next';
@ -214,26 +215,45 @@ export async function confirmExtractAllStreamsDialog() {
return !!value;
}
export async function cleanupFilesDialog() {
const { value } = await Swal.fire({
icon: 'warning',
const CleanupChoices = ({ cleanupChoicesInitial, onChange: onChangeProp }) => {
const [choices, setChoices] = useState(cleanupChoicesInitial);
const getVal = (key) => !!choices[key];
const onChange = (key, val) => setChoices((c) => {
const newChoices = { ...c, [key]: val };
onChangeProp(newChoices);
return newChoices;
});
return (
<div style={{ textAlign: 'left' }}>
<p>{i18n.t('Do you want to move the original file and/or any generated files to trash?')}</p>
<Checkbox label={i18n.t('Trash auto-generated files')} checked={getVal('tmpFiles')} onChange={(e) => onChange('tmpFiles', e.target.checked)} />
<Checkbox label={i18n.t('Trash project CSV')} checked={getVal('projectFile')} onChange={(e) => onChange('projectFile', e.target.checked)} />
<Checkbox label={i18n.t('Trash original source file')} checked={getVal('sourceFile')} onChange={(e) => onChange('sourceFile', e.target.checked)} />
<div style={{ marginTop: 25 }}>
<Checkbox label={i18n.t('Don\'t show dialog again until restarting app')} checked={getVal('dontShowAgain')} onChange={(e) => onChange('dontShowAgain', e.target.checked)} />
</div>
</div>
);
};
export async function cleanupFilesDialog(cleanupChoicesIn = {}) {
let cleanupChoices = cleanupChoicesIn;
const { value } = await ReactSwal.fire({
title: i18n.t('Cleanup files?'),
input: 'radio',
inputValue: 'tmpFiles',
text: i18n.t('Do you want to move the original file and/or any generated files to trash?'),
confirmButtonText: i18n.t('Trash'),
html: <CleanupChoices cleanupChoicesInitial={cleanupChoices} onChange={(newChoices) => { cleanupChoices = newChoices; }} />,
confirmButtonText: i18n.t('Confirm'),
confirmButtonColor: '#d33',
showCancelButton: true,
cancelButtonText: i18n.t('Cancel'),
customClass: { input: 'swal2-losslesscut-radio' },
inputOptions: {
tmpFiles: i18n.t('Trash auto-generated files'),
projectAndTmpFiles: i18n.t('Trash project CSV and auto-generated files'),
all: i18n.t('Trash original source file, project CSV and auto-generated files'),
},
});
return value;
if (value) return cleanupChoices;
return undefined;
}

Loading…
Cancel
Save