Fixed camera mounting issue. Separated media cache modal. Starting working on deleting images after upload. IO-397 IO-398

This commit is contained in:
Patrick Fic
2020-11-17 17:19:17 -08:00
parent 8fc357a6d9
commit ccb42548d0
5 changed files with 175 additions and 75 deletions

View File

@@ -3,6 +3,25 @@ import { all, call, select, takeLatest } from "redux-saga/effects";
import { handleUpload } from "../../util/document-upload.utility";
import PhotosActionTypes from "./photos.types";
export function* onRemovePhotos() {
yield takeLatest(PhotosActionTypes.REMOVE_PHOTOS, removePhotosAction);
}
export function* removePhotosAction({ payload: photoIdsToRemove }) {
try {
const photos = yield select((state) => state.photos.photos);
const fps = photos
.filter((p) => !photoIdsToRemove.includes(p.id))
.map((p) => p.uri);
const all = [];
fps.forEach((f) => all.push(FileSystem.deleteAsync(f)));
yield Promise.all(all);
} catch (error) {
console.log("Saga Error: removePhotos", error);
}
}
export function* onRemoveAllPhotos() {
yield takeLatest(PhotosActionTypes.REMOVE_ALL_PHOTOS, removeAllPhotosAction);
}
@@ -30,6 +49,7 @@ export function* onUploadAllPhotos() {
uploadAllPhotosAction
);
}
export function* uploadAllPhotosAction() {
try {
const photos = yield select((state) => state.photos.photos);
@@ -38,41 +58,39 @@ export function* uploadAllPhotosAction() {
const actions = [];
photos.forEach(async (p) =>
actions.push(
handleUpload(
await handleUpload(
{
file: await (await fetch(p.uri)).blob(),
onError: (props) => {
console.log("Error Callback", props);
},
onProgress: (props) => {
console.log("Progress Calback", props);
},
onSuccess: (props) => {
console.log("Success Calback", props);
},
onError: handleOnError,
onProgress: handleOnProgress,
onSuccess: handleOnSuccess,
},
{
bodyshop: bodyshop,
jobId: p.jobId,
uploaded_by: user.currentUser.email,
callback: (props) => {
console.log("Context Callback", props);
},
photo: {
...p,
name: p.uri.substring(p.uri.lastIndexOf("/") + 1),
},
photo: p,
}
)
)
);
yield Promise.all(actions);
console.log("function*uploadAllPhotosAction -> actions", actions);
} catch (error) {
console.log("Saga Error: onRemoveAllPhotos", error);
}
}
function handleOnError(...props) {
console.log("HandleOnError", props);
}
function handleOnProgress(...props) {
console.log("HandleOnProgress", props);
}
function handleOnSuccess(...props) {
console.log("handleOnSuccess", props);
}
export function* photosSagas() {
yield all([call(onRemoveAllPhotos), call(onUploadAllPhotos)]);
}