First prototype of image upload working. IO-397 IO-398

This commit is contained in:
Patrick Fic
2020-11-17 13:39:31 -08:00
parent 79ec14fe53
commit cd5f8af9e4
15 changed files with 395 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
import { all, call, takeLatest } from "redux-saga/effects";
import PhotosActionTypes from "./photos.types";
import * as FileSystem from "expo-file-system";
import { all, call, select, takeLatest } from "redux-saga/effects";
import { handleUpload } from "../../util/document-upload.utility";
import PhotosActionTypes from "./photos.types";
export function* onRemoveAllPhotos() {
yield takeLatest(PhotosActionTypes.REMOVE_ALL_PHOTOS, removeAllPhotosAction);
@@ -20,11 +21,58 @@ export function* removeAllPhotosAction() {
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* onUploadAllPhotos() {
yield takeLatest(
PhotosActionTypes.UPLOAD_ALL_PHOTOS_START,
uploadAllPhotosAction
);
}
export function* uploadAllPhotosAction() {
try {
const photos = yield select((state) => state.photos.photos);
const bodyshop = yield select((state) => state.user.bodyshop);
const user = yield select((state) => state.user);
const actions = [];
photos.forEach(async (p) =>
actions.push(
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);
},
},
{
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),
},
}
)
)
);
yield Promise.all(actions);
} catch (error) {
console.log("Saga Error: onRemoveAllPhotos", error);
}
}
export function* photosSagas() {
yield all([call(onRemoveAllPhotos)]);
yield all([call(onRemoveAllPhotos), call(onUploadAllPhotos)]);
}