fileStorage: add archive actions

This allows users to back up all files to their computer.
This commit is contained in:
David Lechner
2022-03-02 10:33:21 -06:00
parent 12f34eb210
commit bc7e9e2a20
5 changed files with 209 additions and 1 deletions
+3
View File
@@ -17,6 +17,7 @@ import {
} from '../ble/actions';
import { didFailToSaveAs } from '../editor/actions';
import {
fileStorageDidFailToArchiveAllFiles,
fileStorageDidFailToExportFile,
fileStorageDidFailToInitialize,
fileStorageDidFailToReadFile,
@@ -92,6 +93,7 @@ test.each([
fileStorageDidFailToReadFile('test.file', new Error('test error')),
fileStorageDidFailToWriteFile('test.file', new Error('test error')),
fileStorageDidFailToExportFile('test.file', new Error('test error')),
fileStorageDidFailToArchiveAllFiles(new Error('test error')),
])('actions that should show notification: %o', async (action: AnyAction) => {
const getToasts = jest.fn().mockReturnValue([]);
const show = jest.fn();
@@ -128,6 +130,7 @@ test.each([
'test.file',
new DOMException('test message', 'AbortError'),
),
fileStorageDidFailToArchiveAllFiles(new DOMException('test message', 'AbortError')),
])('actions that should not show a notification: %o', async (action: AnyAction) => {
const getToasts = jest.fn().mockReturnValue([]);
const show = jest.fn();
+13
View File
@@ -19,6 +19,7 @@ import {
} from '../ble/actions';
import { didFailToSaveAs } from '../editor/actions';
import {
fileStorageDidFailToArchiveAllFiles,
fileStorageDidFailToExportFile,
fileStorageDidFailToInitialize,
fileStorageDidFailToReadFile,
@@ -414,6 +415,17 @@ function* showFileStorageFailToExport(
yield* showUnexpectedError(MessageId.FileStorageFailedToExport, action.error);
}
function* showFileStorageFailToArchive(
action: ReturnType<typeof fileStorageDidFailToArchiveAllFiles>,
): Generator {
if (action.error.name === 'AbortError') {
// user clicked cancel button - not an error
return;
}
yield* showUnexpectedError(MessageId.FileStorageFailedToExport, action.error);
}
export default function* (): Generator {
yield* takeEvery(bleDeviceDidFailToConnect, showBleDeviceDidFailToConnectError);
yield* takeEvery(bootloaderDidFailToConnect, showBootloaderDidFailToConnectError);
@@ -429,4 +441,5 @@ export default function* (): Generator {
yield* takeEvery(fileStorageDidFailToReadFile, showFileStorageFailToRead);
yield* takeEvery(fileStorageDidFailToWriteFile, showFileStorageFailToWrite);
yield* takeEvery(fileStorageDidFailToExportFile, showFileStorageFailToExport);
yield* takeEvery(fileStorageDidFailToArchiveAllFiles, showFileStorageFailToArchive);
}