0

I am dispatching an action to upload videos. The action is supposed to run the saga but it does not work as expected. Sometimes the saga runs, sometimes it doesn't. I don't know where exactly is the case the saga won't listen to the action. The first line of handleCompressAndUploadVideo where we have the console log doesn't execute. I guess whenever I reload the app it works but after that subsequent video-upload requests don't run the saga sometimes, but it's not always the case.

export function* handleCompressAndUploadVideo(action) {
  console.log("-------------INSIDE ACTION")
  const {
    path,
    options,
    index,
    apiData,
    data,
    draftVideoId,
    videoId,
  } = action.payload;
  const userToken = yield call(getItemFromStorgae, 'usertoken');
  const isConnected = yield call(checkInternet);
  // yield call(compress, path, options);
  const uri = path; //comdata && comdata.source ? comdata.source : path ? path : null;
  const file = {
    uri: uri,
    name: `${index}.mp4`,
    type: 'video/mp4',
  };
  const vId = data.data.data._id;
  apiData.append('video', file);
  apiData.append('videoId', vId);
  let status;
  console.log("isConnected: ", isConnected)
  if (isConnected) {
    try {
      console.log("before api")
      const response = yield call(
        fetchapi,
        'api/service/upload-video',
        'post',
        apiData,
        userToken,
      );
      console.log("after api")
      status = response.data.status;
      if (response.data.status) {
        yield put(Actions.uploadSuccess(index));
      }
    } finally {
      console.log("here finally", status)
      if (!status) {
        yield put(Actions.setLoadingFalse(draftVideoId, videoId));
        sweetalert('upload error', 'error');
      }
    }
  } else {
    yield put(Actions.setLoadingFalse(draftVideoId, videoId));
    sweetalert('upload error', 'error');
  }
}

function* MentorSaga() {
  yield all([
    yield takeLatest(ActionTypes.SET_LOADING_FALSE, uploadFailed),
    yield takeLatest(
      ActionTypes.COMPRESS_AND_UPLOAD_VIDEO,
      handleCompressAndUploadVideo,
    ),
  ]);
}

1 Answers1

0

Vladimir Serykh just answered the question, but I didn't notice that until later.

Try to remove yield before takeLatest. It's not needed there because takeLatest is not a generator.

Louay Al-osh
  • 3,177
  • 15
  • 28