Files
imexmobile/redux/photos/photos.sagas.js
2020-11-12 21:45:57 -08:00

31 lines
974 B
JavaScript

import { all, call, takeLatest } from "redux-saga/effects";
import PhotosActionTypes from "./photos.types";
import * as FileSystem from "expo-file-system";
export function* onRemoveAllPhotos() {
yield takeLatest(PhotosActionTypes.REMOVE_ALL_PHOTOS, removeAllPhotosAction);
}
export function* removeAllPhotosAction() {
try {
//Physically delete all photosSagas.
const fps = (yield FileSystem.readDirectoryAsync(
FileSystem.documentDirectory + "photos"
)).map((f) => {
return FileSystem.documentDirectory + "photos/" + f;
});
const all = [];
fps.forEach((f) => all.push(FileSystem.deleteAsync(f)));
yield Promise.all(all);
console.log("All photos deleted.");
} catch (error) {
console.log("Saga Error: onRemoveAllPhotos", error);
//yield put(signInFailure(error));
//logImEXEvent("redux_sign_in_failure", { user: email, error });
}
}
export function* photosSagas() {
yield all([call(onRemoveAllPhotos)]);
}