Demo adjustments, resolve upload issues, remove messaging.
This commit is contained in:
@@ -22,3 +22,12 @@ export const uploadSelectedPhotos = (photoIds) => ({
|
||||
type: PhotosActionTypes.UPLOAD_SELECTED_PHOTOS_START,
|
||||
payload: photoIds,
|
||||
});
|
||||
|
||||
export const uploadPhotosSuccess = () => ({
|
||||
type: PhotosActionTypes.UPLOAD_PHOTO_SUCCESS,
|
||||
});
|
||||
|
||||
export const uploadPhotosFailure = (error) => ({
|
||||
type: PhotosActionTypes.UPLOAD_PHOTO_FAILURE,
|
||||
payload: error,
|
||||
});
|
||||
|
||||
@@ -16,6 +16,7 @@ const photosReducer = (state = INITIAL_STATE, action) => {
|
||||
case PhotosActionTypes.REMOVE_ALL_PHOTOS:
|
||||
return {
|
||||
...state,
|
||||
uploadInProgress: false,
|
||||
photos: [],
|
||||
};
|
||||
case PhotosActionTypes.REMOVE_PHOTOS:
|
||||
@@ -29,6 +30,11 @@ const photosReducer = (state = INITIAL_STATE, action) => {
|
||||
uploadInProgress: false,
|
||||
uploadError: action.payload,
|
||||
};
|
||||
case PhotosActionTypes.UPLOAD_PHOTO_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
uploadInProgress: false,
|
||||
};
|
||||
case PhotosActionTypes.UPLOAD_ALL_PHOTOS_START:
|
||||
case PhotosActionTypes.UPLOAD_SELECTED_PHOTOS_START:
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as FileSystem from "expo-file-system";
|
||||
import { all, call, select, takeLatest } from "redux-saga/effects";
|
||||
import { all, call, delay, put, select, takeLatest } from "redux-saga/effects";
|
||||
import { handleUpload } from "../../util/document-upload.utility";
|
||||
import { uploadPhotosFailure, uploadPhotosSuccess } from "./photos.actions";
|
||||
import PhotosActionTypes from "./photos.types";
|
||||
|
||||
export function* onRemovePhotos() {
|
||||
@@ -52,32 +53,38 @@ export function* onUploadAllPhotos() {
|
||||
|
||||
export function* uploadAllPhotosAction() {
|
||||
try {
|
||||
yield delay(500);
|
||||
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) =>
|
||||
photos.forEach(function (p) {
|
||||
actions.push(
|
||||
await handleUpload(
|
||||
{
|
||||
file: await (await fetch(p.uri)).blob(),
|
||||
onError: handleOnError,
|
||||
onProgress: handleOnProgress,
|
||||
onSuccess: handleOnSuccess,
|
||||
},
|
||||
{
|
||||
bodyshop: bodyshop,
|
||||
jobId: p.jobId,
|
||||
uploaded_by: user.currentUser.email,
|
||||
photo: p,
|
||||
}
|
||||
call(
|
||||
handleUpload,
|
||||
...[
|
||||
{
|
||||
uri: p.uri,
|
||||
onError: handleOnError,
|
||||
onProgress: handleOnProgress,
|
||||
onSuccess: handleOnSuccess,
|
||||
},
|
||||
{
|
||||
bodyshop: bodyshop,
|
||||
jobId: p.jobId,
|
||||
uploaded_by: user.currentUser.email,
|
||||
photo: p,
|
||||
},
|
||||
]
|
||||
)
|
||||
)
|
||||
);
|
||||
yield Promise.all(actions);
|
||||
console.log("function*uploadAllPhotosAction -> actions", actions);
|
||||
);
|
||||
});
|
||||
yield all(actions);
|
||||
yield put(removeAllPhotos());
|
||||
yield put(uploadPhotosSuccess());
|
||||
} catch (error) {
|
||||
console.log("Saga Error: onRemoveAllPhotos", error);
|
||||
console.log("Saga Error: uploadAllPhotosAction", error);
|
||||
yield put(uploadPhotosFailure(error));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user