Ask for delete if trash fails #298

pull/304/head
Mikael Finstad 2020-04-10 13:21:25 +08:00
rodzic 8da05e836a
commit 6a8d74f881
1 zmienionych plików z 16 dodań i 2 usunięć

Wyświetl plik

@ -872,15 +872,29 @@ const App = memo(() => {
// eslint-disable-next-line no-alert
if (working || !window.confirm(`${i18n.t('Are you sure you want to move the source file to trash?')} ${filePath}`)) return;
// We can use variables like filePath and html5FriendlyPath, even after they are reset because react setState is async
resetState();
try {
setWorking(true);
await trash(filePath);
// throw new Error('test');
if (html5FriendlyPath) await trash(html5FriendlyPath);
} catch (err) {
toast.fire({ icon: 'error', title: `${i18n.t('Failed to trash source file:')} ${err.message}` });
console.warn('Failed to trash', err);
const { value } = await Swal.fire({
icon: 'warning',
text: i18n.t('Unable to move source file to trash. Do you want to permanently delete it?'),
confirmButtonText: 'Permanently delete',
showCancelButton: true,
});
if (value) {
await unlink(filePath).catch(console.warn);
if (html5FriendlyPath) await unlink(html5FriendlyPath).catch(console.warn);
}
} finally {
resetState();
setWorking(false);
}
}, [filePath, html5FriendlyPath, resetState, working]);