mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 10:35:11 +00:00
fileStorage: add didDeleteFile and didFailToDeleteFile actions
This will allow handling errors if removing a file from storage fails.
This commit is contained in:
@@ -78,12 +78,37 @@ export const fileStorageDidFailToWriteFile = createAction(
|
||||
}),
|
||||
);
|
||||
|
||||
/** Request to delete a file from storage. */
|
||||
/**
|
||||
* Request to delete a file from storage.
|
||||
* @param fileName The name of the file to delete.
|
||||
*/
|
||||
export const fileStorageDeleteFile = createAction((fileName: string) => ({
|
||||
type: 'fileStorage.action.deleteFile',
|
||||
fileName,
|
||||
}));
|
||||
|
||||
/**
|
||||
* Indicates that fileStorageDeleteFile(fileName) succeeded.
|
||||
* @param fileName The name of the file that was deleted.
|
||||
*/
|
||||
export const fileStorageDidDeleteFile = createAction((fileName: string) => ({
|
||||
type: 'fileStorage.action.didDeleteFile',
|
||||
fileName,
|
||||
}));
|
||||
|
||||
/**
|
||||
* Indicates that fileStorageDeleteFile(fileName) failed.
|
||||
* @param fileName The name of the file that should have been deleted.
|
||||
* @param error The error.
|
||||
*/
|
||||
export const fileStorageDidFailToDeleteFile = createAction(
|
||||
(fileName: string, error: Error) => ({
|
||||
type: 'fileStorage.action.didFailToDeleteFile',
|
||||
fileName,
|
||||
error,
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* Request to export (download) a file.
|
||||
* @param fileName The name of the file.
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
fileStorageDeleteFile,
|
||||
fileStorageDidArchiveAllFiles,
|
||||
fileStorageDidChangeItem,
|
||||
fileStorageDidDeleteFile,
|
||||
fileStorageDidExportFile,
|
||||
fileStorageDidFailToArchiveAllFiles,
|
||||
fileStorageDidFailToExportFile,
|
||||
@@ -127,7 +128,10 @@ it('should delete files', async () => {
|
||||
saga.put(fileStorageDeleteFile(testFileName));
|
||||
|
||||
const action = await saga.take();
|
||||
expect(action).toEqual(fileStorageDidRemoveItem(testFileName));
|
||||
expect(action).toEqual(fileStorageDidDeleteFile(testFileName));
|
||||
|
||||
const action2 = await saga.take();
|
||||
expect(action2).toEqual(fileStorageDidRemoveItem(testFileName));
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
|
||||
@@ -15,8 +15,10 @@ import {
|
||||
fileStorageDeleteFile,
|
||||
fileStorageDidArchiveAllFiles,
|
||||
fileStorageDidChangeItem,
|
||||
fileStorageDidDeleteFile,
|
||||
fileStorageDidExportFile,
|
||||
fileStorageDidFailToArchiveAllFiles,
|
||||
fileStorageDidFailToDeleteFile,
|
||||
fileStorageDidFailToExportFile,
|
||||
fileStorageDidFailToInitialize,
|
||||
fileStorageDidFailToReadFile,
|
||||
@@ -156,7 +158,12 @@ function* handleDeleteFile(
|
||||
files: LocalForage,
|
||||
action: ReturnType<typeof fileStorageDeleteFile>,
|
||||
) {
|
||||
yield* call(() => files.removeItem(action.fileName));
|
||||
try {
|
||||
yield* call(() => files.removeItem(action.fileName));
|
||||
yield* put(fileStorageDidDeleteFile(action.fileName));
|
||||
} catch (err) {
|
||||
yield* put(fileStorageDidFailToDeleteFile(action.fileName, ensureError(err)));
|
||||
}
|
||||
}
|
||||
|
||||
function* handleArchiveAllFiles(files: LocalForage): Generator {
|
||||
|
||||
Reference in New Issue
Block a user